diff --git a/__tests__/jest-built-ins.spec.js b/__tests__/jest-built-ins.spec.js index 40ea9d8..4b6050c 100644 --- a/__tests__/jest-built-ins.spec.js +++ b/__tests__/jest-built-ins.spec.js @@ -1,5 +1,5 @@ /*global jest, beforeAll, afterAll */ -jest.mock('node-fetch', () => require('../fetch-mock-jest').sandbox()); +jest.mock('node-fetch', () => require('../server').sandbox()); const fetch = require('node-fetch'); describe('jest built-ins', () => { describe('exposing mock internals', () => { diff --git a/__tests__/jest-extensions.spec.js b/__tests__/jest-extensions.spec.js index b07c234..0998e1a 100644 --- a/__tests__/jest-extensions.spec.js +++ b/__tests__/jest-extensions.spec.js @@ -1,5 +1,5 @@ /*global jest, beforeAll, afterAll */ -jest.mock('node-fetch', () => require('../fetch-mock-jest').sandbox()); +jest.mock('node-fetch', () => require('../server').sandbox()); const fetch = require('node-fetch'); describe('jest extensions', () => { describe('toHaveFetched', () => { diff --git a/browser.js b/browser.js new file mode 100644 index 0000000..c78fed6 --- /dev/null +++ b/browser.js @@ -0,0 +1,4 @@ +const fetchMock = require('fetch-mock/cjs/client.js'); +const jestify = require('./jestify') + +module.exports = jestify(fetchMock); diff --git a/fetch-mock-jest.js b/jestify.js similarity index 97% rename from fetch-mock-jest.js rename to jestify.js index 8df3c1e..9b90fab 100644 --- a/fetch-mock-jest.js +++ b/jestify.js @@ -1,7 +1,6 @@ /*global jest*/ require('./jest-extensions'); -const fetchMock = require('fetch-mock'); const jestify = fetchMockInstance => { const jestifiedInstance = new Proxy(fetchMockInstance, { get: (originalFetchMock, name) => { @@ -98,4 +97,4 @@ const jestify = fetchMockInstance => { return jestifiedInstance; }; -module.exports = jestify(fetchMock); +module.exports = fetchMock => jestify(fetchMock); diff --git a/package.json b/package.json index 7582d7b..88a47b3 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,8 @@ "name": "fetch-mock-jest", "version": "0.0.0", "description": "Jest wrapper for fetch-mock, a comprehensive stub for fetch", - "main": "fetch-mock-jest.js", + "main": "server.js", + "browser": "browser.js", "scripts": { "test": "echo \"Error: no test specified\" && exit 1" }, diff --git a/server.js b/server.js new file mode 100644 index 0000000..a42f591 --- /dev/null +++ b/server.js @@ -0,0 +1,4 @@ +const fetchMock = require('fetch-mock'); +const jestify = require('./jestify') + +module.exports = jestify(fetchMock);