[英]I cannot run multiple test files with Jest?
我今天才開始使用 Jest。 我的__tests__
目錄中有一個簡單的測試文件。 這是當前的測試文件:
describe('ChangeCalendarView', function() {
it('true', function() {
expect(3).toBe(3);
})
});
這運行沒有問題。 當我添加另一個文件時,除了描述之外,代碼完全相同:
describe('ChangeTimePeriod', function() {
it('true', function() {
expect(3).toBe(3);
})
});
然后我得到這個錯誤:
/usr/local/lib/node_modules/jest-cli/node_modules/node-worker-pool/Worker.js:93
throw new Error('Received unexpected data from child process: ' + data);
^
Error: Received unexpected data from child process: {
"error": "Error: ENOENT, open '/usr/local/lib/node_modules/jest-cli/.haste_cache/cache-react-calendar-component'\n\n"
}
at Worker._onStdout (/usr/local/lib/node_modules/jest-cli/node_modules/node-worker-pool/Worker.js:93:11)
這對任何人都有意義嗎?
我使用babel-jest解決了這個問題。 這是我的package.json
{
"name": "myapp",
"version": "0.0.0",
"dependencies": {
"classnames": "^2.1.3",
"dev": "^0.1.3",
"flux": "^2.0.3",
"grunt": "^0.4.5",
"gulp": "^3.9.0",
"immutable": "^3.7.4",
"install": "^0.1.8",
"lodash": "^3.10.0",
"node-simple-static-server": "^1.1.0",
"react-bootstrap": "^0.23.7",
"react-router": "^0.13.3",
"react-router-bootstrap": "^0.18.0",
"react-tools": "^0.13.0-beta.2",
"stackup": "^1.0.1"
},
"devDependencies": {
"babel-jest": "^5.3.0",
"babelify": "^6.1.2",
"browser-sync": "latest",
"browserify-shim": "^3.8.0",
"del": "~0.1.3",
"gulp-autoprefixer": "~1.0.1",
"gulp-bower": "0.0.6",
"gulp-cache": "~0.2.4",
"gulp-imagemin": "latest",
"gulp-jshint": "~1.8.5",
"gulp-load-plugins": "~0.7.0",
"gulp-ruby-sass": "~0.7.1",
"gulp-size": "~1.1.0",
"gulp-strip-debug": "^1.0.2",
"gulp-stylus": "~2.0.1",
"gulp-uglify": "^1.0.2",
"gulp-useref": "~0.4.4",
"gulp-util": "~3.0.1",
"gulp-webserver": "latest",
"jest-cli": "*",
"main-bower-files": "~2.6.2",
"react": "latest",
"react-tools": "latest",
"reactify": "latest",
"strip-debug": "^1.0.1",
"vinyl-source-stream": "^1.0.0",
"watchify": "~2.1"
},
"engines": {
"node": ">=0.10.0"
},
"scripts": {
"test": "jest"
},
"jest": {
"scriptPreprocessor": "../node_modules/babel-jest",
"testFileExtensions": [
"es6",
"js"
],
"moduleFileExtensions": [
"js",
"json",
"es6"
],
"rootDir": "./app",
"collectCoverage": true,
"unmockedModulePathPatterns": [
"react",
"events",
"lodash"
]
},
"browserify": {
"transform": [
"browserify-shim",
[
"reactify",
{
"es6": true
}
]
]
},
"browser": {
"jquery": "./app/bower_components/jquery/dist/jquery.js"
},
"browserify-shim": {
"jquery": "$"
}
}
如果你想指定確切的多個文件來運行測試,只需用空格分隔文件名。
Jest用於檢測測試文件的全局模式。 默認情況下,它會在測試文件夾中查找.js和.jsx文件,以及后綴為.test或.spec的任何文件(例如Component.test.js或Component.spec.js)。 它還會找到名為test.js或spec.js的文件。 因此,使用后綴.test命名您的測試文件,就像pagination.test.js一樣 。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.