I need to test an asynchronous function (redux thunk) in jest. To do this, I decided to use fetchMock. But I'm having problems. The test ends successfully but I get an error from fetch
'fetch-mock: No fallback response defined for POST to http:// *Link* /tmo/rest/user'
Testing block in jest:
it('test: AuthMethod', async () => {
fetchMock.mock(Link, 200);
fetchMock.getOnce('/tmo/rest/user', {
body: JSON.stringify(body),
method: 'POST',
headers: header,
});
store.dispatch(AuthMethod()).then(() => {
let expectedActions = [
{
type: FETCH_AUTH_SUCCESS,
payload: data,
},
];
expect(store.getActions()).toEqual(expectedActions);
});
let value = store.getState();
console.log(value);
});
Fetch-Mock Elements:
body:
const body = {
login: login,
password: password,
deviceSerialNumber: '1111111',
currentAppVersion: AppVersion,
currentDateTime: time,
};
headers:
const header = {
Accept: 'application/json',
'Content-Type': 'application/json',
};