You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Nov 27, 2024. It is now read-only.
I am using ts-jest & want to mock fetch responses (for browser code).
First of all, after installing fetch-mock-jest, in jest setup file I should write global.fetchMock = require('fetch-mock-jest');
is it right or it should be global.fetch = require('fetch-mock-jest').sandbox();?
In ts tests I can't write global.fetchMock or fetchMock without global declaring
or default importing import fetchMock from 'fetch-mock-jest';
But if I am doing such things, why I need to make changes in jest setup script?
Moreover, If I import fetchMock in test, eslint show me suggestion:
Could not find a declaration file for module 'fetch-mock-jest'. ... implicitly has an 'any' type
Try `npm install @types/fetch-mock-jest` if it exists or add a new declaration (.d.ts) file containing `declare module 'fetch-mock-jest'; (ts7016)
Can you provide d.ts file for using typed fetchMock methods?
The text was updated successfully, but these errors were encountered:
and typings/fetch-mock-jest.ts declare module 'fetch-mock-jest';
I have an error:
Test suite failed to run
Jest encountered an unexpected token
This usually means that you are trying to import a file which Jest cannot parse, e.g. it's not plain JavaScript.
...
node_modules\fetch-mock\esm\client.mjs:3552
export default client;
^^^^
SyntaxError: Unexpected token export
at ScriptTransformer._transformAndBuildScript (../node_modules/@jest/transform/build/ScriptTransformer.js:537:17)
at ScriptTransformer.transform (../node_modules/@jest/transform/build/ScriptTransformer.js:579:25)
at Object.<anonymous> (../node_modules/fetch-mock-jest/fetch-mock-jest.js:4:19)
I am using ts-jest & want to mock fetch responses (for browser code).
First of all, after installing fetch-mock-jest, in jest setup file I should write
global.fetchMock = require('fetch-mock-jest');
is it right or it should be
global.fetch = require('fetch-mock-jest').sandbox();
?In ts tests I can't write global.fetchMock or fetchMock without global declaring
or default importing
import fetchMock from 'fetch-mock-jest';
But if I am doing such things, why I need to make changes in jest setup script?
Can you provide d.ts file for using typed fetchMock methods?
The text was updated successfully, but these errors were encountered: