我最初在使用create-react-app时遇到了这个问题,所以我只配置了jest的基本设置:
- created new directory
- yarn init in that directory
- yarn add jest
created new file sum.js:
function sum(a, b) { return a + b; } module.exports = sum;
created file to test above function
const sum = require('./sum'); test('adds 1 + 2 = 3' , () => { expect(sum(1,2)).toBe(3); });
added to package.json:
"scripts": { "test": "jest"
},
但是当我运行yarn test时,会得到以下结果:
terry@terry-sharewalker:~/myProjects/test-jest$ yarn jest
yarn run v1.13.0
$ /home/terry/myProjects/test-jest/node_modules/.bin/jest
接着就没有任何反应了,程序就卡住了。使用create-react-app运行测试时也出现了同样的问题,react-scripts test会显示信息,但是随后什么都没有发生。
以下是收到的内容:
Jest "^24.5.0"
Ubuntu 16.04
yarn 1.13.0
watchman 4.9.0
node 10.15.3
我已经重新安装和升级了所有我能想到的东西,包括npm、node、watchman、linuxbrew、yarn。如果有人能帮助我,我将永远感激不尽!
brew reinstall watchman
就解决了我的问题! ♂️ - Bradley Flood