fetch-mock allows mocking HTTP requests made using fetch, or any one of the many libraries imitating its api such as isomorphic-fetch, node-fetch and fetch-ponyfill.
Questions tagged [fetch-mock]
40 questions
0
votes
0 answers
Redux Jest test fetchMock.getOnce not working
I'm using Redux, fetchMock, redux-mock-store to write a redux action test. Based on this document, https://redux.js.org/recipes/writing-tests, I write my one, but it seems the fetchMock is not working. The get request on the redux action uses the…

Moon
- 790
- 1
- 8
- 19
0
votes
0 answers
fetchMock function makes actual API calls instead of mocking the requests
I am trying to test my signupAction shown below.
import axios from 'axios';
import actionTypes from '../action_types';
import { apiRequest } from '../common_dispatch';
export const signupAction = (user) => async (dispatch) => {
…

Larry
- 1
- 2
0
votes
1 answer
Testing async action called by another async action
I have an async Redux Action that calls another async Redux Action.
I am trying to test this using Jest / Enzyme, but I am getting an error but I am unsure as to why.
First Action - Add Item
This should call the next async action, fetchItemData,…

Pep
- 371
- 2
- 8
- 17
0
votes
1 answer
fetch-mock: log statement interferes with resolution/failure of simple fetch result
When I write the following code, Jest.js passes the test:
test("internalFetch()", async () => {
fetchMock.mock("*", Promise.resolve(JSON.stringify({key1 : "val1"})));
const response = await fetch('http://starMatcher.com', {
method :…

Sean D
- 3,810
- 11
- 45
- 90
0
votes
1 answer
Storybook cannot find fetch-mock module
None of my storybooks stories are working anymore, and I am not sure if its an environmental or code issue.
It cannot find modules in fetch-mock/es5/client.js importing js/modules/es6.*.
The only difference that I can think of is that I added a new…

Oliver Watkins
- 12,575
- 33
- 119
- 225
0
votes
0 answers
Get empty array in redux-mock-store getActions
making a request in my action. Pulling from api that need to return values from mock redux store. I have it start that request when redux mock store dispatch action, but i can't seem the values correctly when store.getActions().
I getting error…

amstriker
- 339
- 7
- 19
0
votes
1 answer
Conditional component import in react application
I'm using fetch-mock to mock the actual component which uses fetch. fetch-mock doesn't support ie11 and would like to import the example component only if the browser is supported. How can i achieve that ?
ABCExampleComponent uses fetch-mock for…

Mad-D
- 4,479
- 18
- 52
- 93
0
votes
1 answer
Getting an error when running two fetch-mock tests using enzyme and jest
I have am testing a React component with jest and enzyme using fetch-mock. But when I try to run two tests for the I get this error.
FAIL ./user.test.js
User
✓ it shows the loading text before the data is fetched (2ms)
✕ shows…

Amen Ra
- 2,843
- 8
- 47
- 85
-1
votes
1 answer
Jest testing conditional response
I have data
const data = {
animal: 'cat',
isBlack: true
}
What I wish my component to render some text if the cat is black and not to render if the cat is not black. I have several tests
describe('About', () => {
const data = {
animal:…

Katharina Schreiber
- 1,187
- 2
- 11
- 38
-3
votes
2 answers
Typescript complaining after passing ...args as argument to a function
I'm using fetch-mock library to build my own utils.
When defining a new function and passing args to fetchMock.mock function, I get this error:
A spread argument must either have a tuple type or be passed to a rest
parameter
export function…

EugenSunic
- 13,162
- 13
- 64
- 86