camsong / fetch-jsonp

Make JSONP request like window.fetch
998 stars 158 forks source link

How to mock using nock or any other? #42

Closed sanjitbauli closed 7 years ago

sanjitbauli commented 7 years ago
ReferenceError: window is not defined
camsong commented 7 years ago

Nock doesn't support jsonp right now https://github.com/node-nock/nock/issues/761 , you can use https://github.com/tmpvar/jsdom to get ride of window undefined error in node environment

bartvde commented 6 years ago

does anyone have an example on how to mock this? TIA

bartvde commented 6 years ago

ah I got it to work with something like this combined with nock in jest:

// __mocks__/fetch-jsonp.js
'use strict';

const fetchjsonp = jest.genMockFromModule('fetch-jsonp');

module.exports = function(url) {
  return fetch(url);
};