我正在尝试在一个新的React项目中设置Jest。
的package.json:
"dependencies" : {
"react": "^0.13.1",
"jest-cli": "^0.4.5",
"babel-jest": "^5.2.0"
},
"scripts": {
"test": "jest"
},
"jest": {
"scriptPreprocessor": "<rootDir>/static/preprocessor.js",
"unmockedModulePathPatterns": ["react"],
"testFileExtensions": [
"js",
"jsx"
],
"moduleFileExtensions": [
"js",
"json",
"jsx"
],
"testPathDirs": [
"<rootDir>/static/app"
],
"testDirectoryName": "test",
"testPathIgnorePatterns": [
"/node_modules/",
"/bower_components/"
]
}
试验test.js:
jest.dontMock('../scripts/components/shared/Test');
describe('Test', () => {
var Test = require('../scripts/components/shared/Test');
it('registers test', () => {
expect("yes").toEqual("yes");
});
});
Test.jsx:
var React = require('react');
当我在上面运行npm test
时,我得到以下内容:
My-MacBook-Pro:project user$ npm test
> Project@0.0.1 test /Users/user/Projects/project
> jest
Using Jest CLI v0.4.5
Waiting on 1 test...My-MacBook-Pro:project user$
如果我将Test.jsx更改为require('lodash')
,我会得到以下内容:
My-MacBook-Pro:project user$ npm test
> Project@0.0.1 test /Users/user/Projects/project
> jest
Using Jest CLI v0.4.5
PASS static/app/test/Test-test.js (0.517s)
1 test passed (1 total)
Run time: 0.731s
My-MacBook-Pro:project user$
似乎添加'react'模块会导致Jest崩溃(没有任何登录终端)。我怀疑我的配置有问题,但我似乎找不到什么。
此外,有没有办法获得更详细的日志记录?现在它崩溃没有输出...我打赌如果我有某种输出我可以更好地调查。