1

我需要开玩笑地测试一个异步函数(redux thunk)。为此,我决定使用 fetchMock。但我遇到了问题。测试成功结束,但我从 fetch 中得到一个错误

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

开玩笑的测试块:

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

获取模拟元素:

身体:

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

标题:

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

0 回答 0