Skip to content

Commit

Permalink
fix(test): repair test
Browse files Browse the repository at this point in the history
  • Loading branch information
Dimitri Kopriwa committed Feb 7, 2019
1 parent beb7107 commit d4eee4c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
13 changes: 3 additions & 10 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,12 @@ export function polyfill(options) {
const fetch = require('fetch-cookie')(require('isomorphic-fetch'), cookieJar);
global.fetch = fetch;
global.cookieJar = cookieJar;
global.fetchMock = undefined;
const { Response, Headers, Request } = require('whatwg-fetch');
global.Response = Response;
global.Headers = Headers;
global.Request = Request;
require('whatwg-fetch');
}

if (opts.fetch) {
const { Response, Headers, Request } = require('whatwg-fetch');
if (opts.fetch && !opts.isomorphicFetch) {
require('whatwg-fetch');
global.fetchMock = require('fetch-mock');
global.Response = Response;
global.Headers = Headers;
global.Request = Request;
}

if (opts.localStorage && !global.localStorage) {
Expand Down
7 changes: 7 additions & 0 deletions src/tests/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ describe('polyfill', () => {
expect(global.Response).not.toBeDefined();
polyfill({
media: false,
isomorphicFetch: false,
fetch: true,
localStorage: false,
});
Expand All @@ -38,7 +39,10 @@ describe('polyfill', () => {

it('should polyfill fetch', (done) => {
polyfill({
media: false,
isomorphicFetch: true,
fetch: false,
localStorage: false,
});
expect(global.Headers).toBeDefined();
expect(global.Request).toBeDefined();
Expand All @@ -51,6 +55,9 @@ describe('polyfill', () => {

it('should not polyfill localStorage', () => {
polyfill({
media: false,
isomorphicFetch: false,
fetch: false,
localStorage: false,
});
expect(global.localStorage).toBeDefined();
Expand Down

0 comments on commit d4eee4c

Please # to comment.