Skip to content

Commit

Permalink
Trying to migrate to fetch-mock#501 export error
Browse files Browse the repository at this point in the history
  • Loading branch information
Пинчук Виталий А authored and Пинчук Виталий А committed Jan 28, 2020
1 parent 631c2d2 commit 4a1eb3b
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 50 deletions.
110 changes: 83 additions & 27 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "systemjs-ts-es6-vue",
"version": "0.6.5",
"version": "0.7.0",
"repository": {
"type": "git",
"url": "https://github.com/viT-1/systemjs-ts-es6-vue.git"
Expand Down Expand Up @@ -88,7 +88,7 @@
"hjson": "3.2.1",
"html-loader-jest": "0.2.1",
"jest": "25.1.0",
"jest-fetch-mock": "3.0.1",
"fetch-mock": "8.3.2",
"merge-stream": "2.0.0",
"ts-jest": "25.0.0",
"ts-node": "8.6.2",
Expand Down
7 changes: 0 additions & 7 deletions src/jest.setup.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1 @@
import { GlobalWithFetchMock } from 'jest-fetch-mock';

const customGlobal: GlobalWithFetchMock = global as GlobalWithFetchMock;
customGlobal.fetch = require('jest-fetch-mock');

customGlobal.fetchMock = customGlobal.fetch;

(global as any).VueMultiselect = require('vue-multiselect');
18 changes: 4 additions & 14 deletions src/services/SomeSvc/SomeSvc.spec.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,19 @@
import { FetchMock } from 'jest-fetch-mock';
import fetchMock from 'fetch-mock';
import { IOption as ISomeValue } from '@common/IamSelect/IamSelect.option.i';

import { SomeSvc } from './SomeSvc';
import { IRespSomeOther } from './respSome.other.i';

const fetchMock = fetch as FetchMock;
const respMock: IRespSomeOther = {
imports: {
foo: 'some',
bar: 'thing',
},
};

fetchMock.mockImplementation((url) => {
switch (url) {
case '/not-ok':
return Promise.reject(
new Response(JSON.stringify('not-ok'), { status: 500, statusText: 'NOT OK' }),
);

default:
return Promise.resolve(
new Response(JSON.stringify(respMock)),
);
}
fetchMock.mock({
url: '/fetch-resp.json',
response: Promise.resolve(JSON.stringify(respMock)),
});

describe('service SomeSvc', () => {
Expand Down

0 comments on commit 4a1eb3b

Please sign in to comment.