测试Redux动作以匹配期望但失败

时间:2020-10-22 09:47:24

标签: redux

我正在学习如何编写测试,并查看redux文档以编写类似于docs的测试。 我的项目是通过create-react-app创建的。

我模仿的是: https://redux.js.org/recipes/writing-tests

我的代码:

import configureMockStore from "redux-mock-store";
import thunk from "redux-thunk";
import * as actions from "../app/store/account/actions";
import * as actionTypes from "../app/store/account/actionTypes";
import fetchMock from "fetch-mock-jest";

const middlewares = [thunk];
const mockStore = configureMockStore(middlewares);

describe("async actions", () => {
  it("create GET_ACCOUNT_IMAGE when fetching images has been done", () => {
    fetchMock.get("https://aws.random.cat/meow", 200);
    const expectedActions = [
      { type: actionTypes.START_FETCH_ACCOUNT_IMAGE },
      { type: actionTypes.GET_ACCOUNT_IMAGE },
    ];

    const store = mockStore({});
    return store
      .dispatch(actions.getAccountImage("https://aws.random.cat/meow"))
      .then(() => {
        // return of async actions
        expect(store.getActions()).toEqual(expectedActions);
      });
  });
});

我的错误消息: enter image description here

0 个答案:

没有答案