我正在尝试使用 Jest 创建以下单元测试。
jest.dontMock("pointsAwardingActions.js");
describe("points awarding actions", () => {
describe("award points", () => {
it("should dispatch begin ajax action", () => {
var pointsAwardingActions = require("pointsAwardingActions.js");
const mockedDispatch = jest.fn();
});
});
});
但运行后出现以下错误npm test
.
类型错误:jest.fn 不是函数
这是我的一些部分package.json
:
{
"scripts": {
"test": "jest"
},
"author": "alayor",
"license": "ISC",
"jest": {
"scriptPreprocessor": "<rootDir>/node_modules/babel-jest",
"testFileExtensions": ["spec.js"],
"moduleFileExtensions": ["js"],
"collectCoverage": "true"
},
"dependencies": {
"babel-cli": "6.8.0",
"babel-core": "6.8.0",
"babel-jest": "^6.0.1",
"babel-loader": "6.2.4",
"babel-plugin-react-display-name": "2.0.0",
"babel-polyfill": "6.8.0",
"babel-preset-es2015": "6.6.0",
"babel-preset-react": "6.5.0",
"babel-preset-react-hmre": "1.1.1",
"expect": "1.19.0",
"express": "4.13.4",
"jest": "^0.1.40",
"jest-cli": "^0.8.1",
...
}
}
我收到该错误的原因可能是什么?