fetch-mock-jest | Jest wrapper for fetch-mock , a comprehensive stub for fetch | Mock library
kandi X-RAY | fetch-mock-jest Summary
kandi X-RAY | fetch-mock-jest Summary
Jest wrapper for fetch-mock, a comprehensive stub for fetch
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of fetch-mock-jest
fetch-mock-jest Key Features
fetch-mock-jest Examples and Code Snippets
Community Discussions
Trending Discussions on fetch-mock-jest
QUESTION
I am trying to unit test a function which sends a post request then the API returns a json object. I am trying to do this using jest and fetch-mock-jest.
Now instead of the expected payload the tested function receives {"size":0,"timeout":0}
and throws error invalid json response body at reason: Unexpected end of JSON input
. Pretty sure there is something basic I don't see. I spent way more time on this without any progress than I'd like to admit.
Edit: I am pretty new to jest and unit testing in general, so if someone has a better suggestion to go about mocking fetch, please tell me.
Test File
...ANSWER
Answered 2021-Feb-03 at 02:09You can use jest.mock(moduleName, factory, options) to mock isomorphic-unfetch
module by yourself. Don't need fetch-mock-jest
module.
E.g.
main.ts
:
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install fetch-mock-jest
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page