Ale*_*kov 3 node.js npm jestjs
我只是想使用Jest作为单元测试框架.我从官方的ReactJS方面做了一些示例.
function sum(value1, value2) {
return value1 + value2;
}
module.exports = sum;
----------------------------------------------------------------
jest.dontMock('../sum');
describe('sum', function() {
it('adds 1 + 2 to equal 3', function() {
var sum = require('../sum');
expect(sum(1, 2)).toBe(3);
});
});
Run Code Online (Sandbox Code Playgroud)
但是当我运行npm测试时,我得到了下一个错误:
/home/app.local/node_modules/jest-cli/bin/jest.js:12
const fs = require('fs');
^^^^^
SyntaxError: Use of const in strict mode.
at Module._compile (module.js:439:25)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Function.Module.runMain (module.js:497:10)
at startup (node.js:119:16)
at node.js:902:3
npm ERR! Test failed. See above for more details.
npm WARN This failure might be due to the use of legacy binary "node"
npm WARN For further explanations, please read
/usr/share/doc/nodejs/README.Debian
Run Code Online (Sandbox Code Playgroud)
出了什么问题?
如果您阅读了您发布的链接的文档,您可以看到它说明如下:
Jest使用ES2015功能,并且需要运行至少4.0.0的Node.js版本.
您的版本0.10.25可能是您遇到问题的原因.将您的版本升级到> = 4.0.0应解决此问题.
| 归档时间: |
|
| 查看次数: |
2701 次 |
| 最近记录: |