kopia lustrzana https://gitlab.com/rysiekpl/libresilient
fetch() test passes
rodzic
4c6245a672
commit
5a18502bad
|
@ -1,8 +1,15 @@
|
|||
const makeServiceWorkerEnv = require('service-worker-mock');
|
||||
|
||||
const fetch = require('jest-fetch-mock');
|
||||
fetch.enableMocks()
|
||||
jest.setMock('node-fetch', fetch);
|
||||
global.fetch = require('node-fetch');
|
||||
jest.mock('node-fetch', () => {
|
||||
const context = {
|
||||
then: jest.fn().mockImplementationOnce(() => {
|
||||
const response = { test: "success" };
|
||||
return Promise.resolve(response);
|
||||
})
|
||||
};
|
||||
return jest.fn(() => context);
|
||||
});
|
||||
|
||||
describe("plugin: fetch", () => {
|
||||
beforeEach(() => {
|
||||
|
@ -25,8 +32,6 @@ describe("plugin: fetch", () => {
|
|||
|
||||
test("it should return data from fetch()", async () => {
|
||||
require("../../plugins/fetch.js");
|
||||
|
||||
fetch.mockResponse(JSON.stringify({test: "success"}));
|
||||
|
||||
const returnedJSON = await self.LibResilientPlugins[0].fetch('https://resilient.is/test.json');
|
||||
expect(returnedJSON).toEqual({test: "success"})
|
||||
|
|
|
@ -1250,15 +1250,6 @@
|
|||
"safe-buffer": "5.1.2"
|
||||
}
|
||||
},
|
||||
"cross-fetch": {
|
||||
"version": "3.1.4",
|
||||
"resolved": "https://registry.npmjs.org/cross-fetch/-/cross-fetch-3.1.4.tgz",
|
||||
"integrity": "sha512-1eAtFWdIubi6T4XPy6ei9iUFoKpUkIF971QLN8lIvvvwueI65+Nw5haMNKUwfJxabqlIIDODJKGrQ66gxC0PbQ==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"node-fetch": "2.6.1"
|
||||
}
|
||||
},
|
||||
"cross-spawn": {
|
||||
"version": "7.0.3",
|
||||
"resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.3.tgz",
|
||||
|
@ -2282,16 +2273,6 @@
|
|||
"jest-util": "27.0.6"
|
||||
}
|
||||
},
|
||||
"jest-fetch-mock": {
|
||||
"version": "3.0.3",
|
||||
"resolved": "https://registry.npmjs.org/jest-fetch-mock/-/jest-fetch-mock-3.0.3.tgz",
|
||||
"integrity": "sha512-Ux1nWprtLrdrH4XwE7O7InRY6psIi3GOsqNESJgMJ+M5cv4A8Lh7SN9d2V2kKRZ8ebAfcd1LNyZguAOb6JiDqw==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"cross-fetch": "3.1.4",
|
||||
"promise-polyfill": "8.2.0"
|
||||
}
|
||||
},
|
||||
"jest-get-type": {
|
||||
"version": "27.0.6",
|
||||
"resolved": "https://registry.npmjs.org/jest-get-type/-/jest-get-type-27.0.6.tgz",
|
||||
|
@ -3111,12 +3092,6 @@
|
|||
"integrity": "sha512-7PiHtLll5LdnKIMw100I+8xJXR5gW2QwWYkT6iJva0bXitZKa/XMrSbdmg3r2Xnaidz9Qumd0VPaMrZlF9V9sA==",
|
||||
"dev": true
|
||||
},
|
||||
"promise-polyfill": {
|
||||
"version": "8.2.0",
|
||||
"resolved": "https://registry.npmjs.org/promise-polyfill/-/promise-polyfill-8.2.0.tgz",
|
||||
"integrity": "sha512-k/TC0mIcPVF6yHhUvwAp7cvL6I2fFV7TzF1DuGPI8mBh4QQazf36xCKEHKTZKRysEoTQoQdKyP25J8MPJp7j5g==",
|
||||
"dev": true
|
||||
},
|
||||
"prompts": {
|
||||
"version": "2.4.1",
|
||||
"resolved": "https://registry.npmjs.org/prompts/-/prompts-2.4.1.tgz",
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
"devDependencies": {
|
||||
"eslint": "^7.32.0",
|
||||
"jest": "^27.0.6",
|
||||
"jest-fetch-mock": "^3.0.3",
|
||||
"node-fetch": "^2.6.1",
|
||||
"service-worker-mock": "^2.0.5"
|
||||
},
|
||||
"dependencies": {}
|
||||
|
|
Ładowanie…
Reference in New Issue