-
Notifications
You must be signed in to change notification settings - Fork 119
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Problem with typescript import #82
Comments
@Spiralis How do you import jest-fetch-mock ?
And things go match better. |
I've created a PR to improve the typings |
This one should be closed now that #99 has been merged. My bad for not mentioning it in the commit message! |
Closing now |
I still appear to be having the same issue. I'm using:
with Tsconfig.json { and jest.config.js module.exports = { and this in setupJest.ts import { GlobalWithFetchMock } from "jest-fetch-mock"; const customGlobal: GlobalWithFetchMock = global as GlobalWithFetchMock; any thoughts on how to fix this? |
I can confirm that I am also getting this issue, with 2.1.0, and that adding |
Presumably that will mean i have the swap all my fetch calls with fetchAny?
I was hoping to using this with in some integration tests and that would be
a lot of work.
…On Fri, 18 Jan 2019, 21:29 Angelika Olsson ***@***.*** wrote:
I can confirm that I am also getting this issue, with 2.1.0, and that
adding
const fetchAny = fetch as any;
is a workaround.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#82 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/Al2dxcfdX6u4B9kNcOM5MbLIfaafZrn5ks5vEYXRgaJpZM4Vvh5p>
.
|
I just want to share steps i've been through to setup jest-fetch-mock in Typescript for Node.js environment that might be related to this issue.
do this instead
I'm not sure why the documentation uses fetch instead, i'd love someone to explain more about this subject. Hope it helps! Cheers! |
For anyone reading, instead of doing
and that still preserves the types while fixing the issue. |
You can also do add a "global.d.ts" file to the root of your repository with the text |
This comment is a life savior. Thanks |
As a part of my build routine I call
tsc --noEmit
.Earlier this printed nothing to my command-line.
I added jest-fetch-mock to my project, used a setupFile with
global.fetch = require('jest-fetch-mock')
as recommended.If I dont add an import statement for the jest-fetch-mock in the typescript source test files where the jest-fetch-mock of fetch is used, then:
Property 'resetMocks' does not exist on type '(input?: string | Request, init?: RequestInit) => Promise<Response>'.
If I do add an import statement for the jest-fetch-mock in the typescript source test files where the jest-fetch-mock of fetch is used, then:
node_modules/@types/jest/index.d.ts:34:15 - error TS2451: Cannot redeclare block-scoped variable 'expect'.
plus many error messages after this (which I guess is caused for the same reason).The only work-around I know for this is to add a
const fetchAny = fetch as any;
at the top of the source test-files where I want to use jest-fetch-mock, and use that object instead to do the testing.Which is not ideal. The whole purpose of the typescript types is to be able to benefit from the typings. Casting to any means that it becomes an ordinary object.
Has anyone encountered this and found any better solutions?
The text was updated successfully, but these errors were encountered: