0
我試圖進入單元測試,但考試的時候,當我嘗試測試我的代碼,我在終端得到這個:無效的或意外的標記「」試圖用摩卡
D:\VS Code\VS Code\tests\test\test.js:1
(function (exports, require, module, __filename, __dirname) { ��'
^
SyntaxError: Invalid or unexpected token
at createScript (vm.js:56:10)
at Object.runInThisContext (vm.js:97:10)
at Module._compile (module.js:542:28)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
at Module.require (module.js:497:17)
at require (internal/module.js:20:19)
at C:\Users\SSD\AppData\Roaming\npm\node_modules\mocha\lib\mocha.js:230:27
at Array.forEach (native)
at Mocha.loadFiles (C:\Users\SSD\AppData\Roaming\npm\node_modules\mocha\lib\mocha.js:227:14)
at Mocha.run (C:\Users\SSD\AppData\Roaming\npm\node_modules\mocha\lib\mocha.js:495:10)
at Object.<anonymous> (C:\Users\SSD\AppData\Roaming\npm\node_modules\mocha\bin\_mocha:469:18)
at Module._compile (module.js:570:32)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
at Module.runMain (module.js:604:10)
at run (bootstrap_node.js:389:7)
at startup (bootstrap_node.js:149:9)
at bootstrap_node.js:504:3
我跟着摩卡文檔在這裏給出的步驟: https://mochajs.org/#installation
- NPM安裝摩卡
- 的mkdir測試
- $空>測試/ test.js
然後,我從字面上複製和粘貼的例子
var assert = require('assert');
describe('Array', function() {
describe('#indexOf()', function() {
it('should return -1 when the value is not present', function() {
assert.equal(-1, [1,2,3].indexOf(4));
});
});
});
成立的package.json測試:
"scripts": {
"test": "mocha"
}
然後運行命令npm test
不管我拿錯誤的測試例子是一樣的。我也嘗試卸載並再次安裝摩卡,我也嘗試過柴。同樣的錯誤。
我也有VSCode這個問題。我認爲文件編碼出了問題。我最終將文本內容複製到一個新文件中,之後就沒事了。 –