【发布时间】:2019-08-26 16:30:03
【问题描述】:
我有一个从 create-react-app 启动的 react-redux 应用程序。据我了解,运行 jest 所需的内容已经在 create-react-app 中为您配置(即 webpack 文件、babel 等)。
所以我创建了一个名为CreateQueryActions.test.js 的测试套件,该文件包含一个包含所有必要组件的测试套件(据我所知) - 描述/它/预期。
当我运行 npm run test 时,jest 看到了该文件,但它以 Test suite failed to run Your test suite must contain at least one test. 失败
但它确实有一个测试。那么这里发生了什么?
import { tableList } from "../../utils/CreateQueryMockData";
import * as createQueryActions from "./CreateQueryActions";
import thunk from "redux-thunk";
import fetchMock from "fetch-mock";
import configureMockStore from 'redux-mock-store';
//Async test dependencies
const middleware = [thunk];
const mockStore = configureMockStore(middleware);
describe("create query API calls", () => {
afterEach(() => {
/*Its importatnt to keep this test atomic.
* This initialized fetchMock for each test -
* needs to be reset after each test has ran
* */
fetchMock.restore();
});
it("should create a 'GET_TABLE_LIST' action", () => {
fetchMock.mock("*", {
body: tableList,
headers: { "content-type": "application/json" }
});
const expectedAction = [
{ type: "GET_TABLE_LIST" }
];
const store = mockStore({ tableList: [] });
return store.dispatch(createQueryActions.getTableList()).then(() => {
expect(store.getActions()).toEqual(expectedAction);
});
});
});
PACKAGE.JSON
{
"name": "queryapp",
"version": "1.0.0",
"private": true,
"dependencies": {
"axios": "^0.19.0",
"bootstrap": "^4.3.1",
"history": "^4.9.0",
"http-proxy-middleware": "^0.19.1",
"jest": "^24.7.1",
"oidc-client": "^1.8.2",
"react": "^16.8.6",
"react-bootstrap": "^1.0.0-beta.5",
"react-csv": "^1.1.1",
"react-dom": "^16.8.6",
"react-redux": "^5.1.1",
"react-router-dom": "^5.0.1",
"react-scripts": "3.0.1",
"react-table": "^6.10.0",
"redux": "^4.0.4",
"redux-form": "^7.4.2",
"redux-form-validators": "^2.7.5",
"redux-oidc": "^3.1.2",
"redux-thunk": "^2.3.0"
},
"devDependencies": {
"fetch-mock": "^7.3.9",
"redux-immutable-state-invariant": "^2.1.0",
"redux-logger": "^3.0.6",
"redux-mock-store": "^1.5.3"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": "react-app"
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
}
}
【问题讨论】:
标签: redux react-redux jestjs