我只是試圖使用Jest作爲單元測試框架。 我做了,並從官方ReactJS side的例子。與'npm測試'JEST失敗與「在嚴格模式下使用const」
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);
});
});
但是當我運行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
到底哪裏出問題了?
您使用的是什麼版本的節點? – saadq
節點版本是v0.10.25 – AlexeiBerkov