React Native Jest:未定义测试(测试)

时间:2021-01-20 09:15:12

标签: reactjs react-native jestjs babeljs

我正在尝试使用 Jest 运行最基本的示例,但我似乎无法运行。按照此处的说明进行操作:https://jestjs.io/docs/en/getting-started.html

这是我的代码:

import Actions, {
  reducer,
  INITIAL_STATE,
} from "../../App/Redux/AcModelDeleteRedux";

test("request", () => {
  const data = [];
  const state = reducer(INITIAL_STATE, Actions.acModelDeleteRequest(data));
  expect(state.fetching).toBe(true);
  expect(state.data).toStrictEqual(data);
  expect(state.error).toBeNull();
});

test("success", () => {
  const payload = [];
  const state = reducer(INITIAL_STATE, Actions.acModelDeleteSuccess(payload));
  expect(state.fetching).toBe(false);
  expect(state.payload).toStrictEqual(payload);
  expect(state.error).toBeNull();
});

test("failure", () => {
  const state = reducer(INITIAL_STATE, Actions.acModelDeleteFailure());
  expect(state.fetching).toBe(false);
  expect(state.error).toStrictEqual(true);
  expect(state.payload).toBeNull();
});

enter image description here

2 个答案:

答案 0 :(得分:0)

节点和笑话版本不匹配可能导致错误。 https://github.com/facebook/jest/issues/9538

答案 1 :(得分:-1)

在 Jest 测试中,文件扩展名必须是 .test.js 。您需要将文件扩展名更改为 .test.js