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
2
votes
0 answers
React Native & Jest: How to properly test a component that calls fetch in useEffect. "Can't access .root on unmounted test renderer"
I want to test my component in Jest and that it is displaying fetched data correctly. I have the following component, which has a useEffect hook that calls a function called getData. getData fetches to the back end API, converts the response to…

Scott
- 1,207
- 2
- 15
- 38
2
votes
2 answers
Unable to mock node-fetch using fetch-mock
I am trying to do unit testing for a simple function which sends a get request, receives a response and then returns a promise object with the success or the failure message. Following is the function:
module.exports.hello = async (event, context)…

Abhijeet Kharkar
- 73
- 1
- 12
2
votes
1 answer
Testing React Redux Async Actions with fetch-mock - "Cannot read property 'then' of undefined"
I have some problems with testing react redux async actions, for some reason store.dispatch returns undefined and .then method doesn't work.
When I console.log the store.dispatch(actions.requestChartData()) it gives me the following error:…

codeKid
- 75
- 2
- 12
1
vote
0 answers
How to test react component mocking fetch api?
I'm trying to test a react component where a fetch call occurs. The component:
class SearchResults extends React.Component<{ tag: string; setSpinner: (value: boolean) => void }> {
state: searchResultsState = {
results: [],
tag: '',
…

Oksana
- 25
- 5
1
vote
0 answers
Getting Error `TypeError: debug is not a function` while running the test cases in Jest
I have been getting the below error whenever i run jest jest --coverage;
Stackoverflow says that i can't add images to my post yet. So please open the link to view the error. Thanks
Click here to view error's screenshot
Code and configurations are…

akarshan gupta
- 31
- 3
1
vote
0 answers
Network Error when running multiple unit tests that utilise fetch-mock
I'm using fetch-mock (v.9.11.0) with React Testing Library to test a login form component, and as soon as I have more than 2 unit tests that have a mocked fetch response I start getting ECONNREFUSED errors, and my tests fail with a Network Error…

MassivePenguin
- 3,701
- 4
- 24
- 46
1
vote
1 answer
fetch-mock-jest .post resolves to {"size":0,"timeout":0}
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…

bold_yet_unwise
- 58
- 7
1
vote
2 answers
Cannot test AsyncTypeahead from react-bootstrap-typeahead with Enzyme
I am trying to test AsyncTypeahead from react-bootstrap-typeahead.
I have a very simple test component :
class AsyncTypeahead2 extends Component {
constructor(props: Props) {
super(props);
this.state = {
…

Oliver Watkins
- 12,575
- 33
- 119
- 225
1
vote
1 answer
Typescript + Karma + Fetch Mock
Trying to import fetch mock but when karma starts I get:
You need to include some adapter that implements karma.start method!
I've tried all of these with no success:
import {fetchMock} from 'fetch-mock';
import fetchMock from 'fetch-mock';
import…

Scott Walter
- 9,426
- 4
- 18
- 23
1
vote
1 answer
React-Redux Testing with Jest: Received Payload = undefined
I am trying to learn/implement jest testing into my react-redux application. My test fails saying that the received does not equal what was expected, however, the actual thunk works and returns data to my application. So I've either written the test…

reactFullStackDeveloper
- 829
- 2
- 15
- 32
1
vote
1 answer
fetchMock: uncaught typeError
I have mocked my API-Respones with fetchMock (v.5.13.1). I have been working with it for a quite long time now and I didn't see this kind of behaviour yet.
I mocked two GET responses that are very…

Aleks
- 101
- 1
- 12
1
vote
1 answer
Action call is returning 'undefined' with fetch-mock
Action "type": undefined, is what I keep getting returned when I try to test a redux action with fetch-mock. Any suggestion on how to resolve this issue? Could it be a bug in fetch-mock?
Expected value to equal:
[{"type": undefined}, {"result":…

abc903
- 37
- 1
- 1
- 5
1
vote
1 answer
Why does Redux Promise Middleware not dispatch a rejected action for my example code?
I use fetch-mock, redux-mock-store, promise-middleware to test the redux implementation of my application. I have following code:
import configureMockStore from 'redux-mock-store';
import promiseMiddleware from 'redux-promise-middleware';
import…

1nsg
- 109
- 1
- 9
1
vote
0 answers
Mocking fetch POST
I am writing test case for below function:
handleShare(response, payload) {
ShareUtils.listUsers()
.then((users) => {
users.forEach(user => userList.push({
name: user.name,
id: user.id)
…

Bhuwan
- 225
- 5
- 15
0
votes
1 answer
How to test asynchronous action?
I have an action:
export const GetChatList = userStatus => {
return dispatch => {
dispatch({
type: MessagesActionTypes.GET_MESSAGES_LIST.REQUEST,
payload: {}
});
axios
.get(config.apiUrl +…

Батрадз Санакоев
- 67
- 1
- 5