I
I
ilyaux2020-06-13 16:46:06
Unit testing
ilyaux, 2020-06-13 16:46:06

No fallback response defined for POST. How to solve fetch-mock problem?

I need to test an async function (redux thunk) in jest. For this I use fetchMock. But I'm having problems. The test succeeds but I get an error from fetch

fetch-mock: No fallback response defined for POST to http:// *Link* /tmo/rest/user'


Test 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);
  });


console log
FetchAuthLoading: false,
FetchAuthSuccess: false,
FetchAuthFailure: true,
AuthData: [],
AuthErros: fetch-mock: No fallback response defined for POST to http:// *Link* /tmo/rest/user'


fetch-mock:

const body = {
  login: login,
  password: password,
  deviceSerialNumber: '1111111',
  currentAppVersion: AppVersion,
  currentDateTime: time,
};


const header = {
  Accept: 'application/json',
  'Content-Type': 'application/json',
};

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question