javascript - 运行 node.js mocha 测试时意外的 token 非法

标签 javascript node.js mocha.js

我找遍了,但还没有弄清楚我做错了什么。我正在尝试设置 mocha 来测试 node.js javascript 应用程序文件。我已经安装了 Node 并成功地在其上运行了基本的东西以确认它正在工作。

我在我的项目文件中安装了 mocha,并且在我的项目文件中还有一个 Makefile 和一个名为“test”的文件。

这是我的终端 (osx 10) 在运行命令“make test”时吐出的错误。

    humbleMousesMBP:chapter02 humbleMouse$ make test

    /Users/humbleMouse/chapter02/test/exchange.test.js:22

        ^
        SyntaxError: Unexpected token ILLEGAL
        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 Module.require (module.js:364:17)
        at require (module.js:380:17)
        at /Users/humbleMouse/chapter02/node_modules/mocha/bin/_mocha:313:27
        at Array.forEach (native)
        at load (/Users/humbleMouse/chapter02/node_modules/mocha/bin/_mocha:310:9)
        at Object.<anonymous> (/Users/humbleMouse/chapter02/node_modules/mocha           /bin/_mocha:301:1)
        at Module._compile (module.js:456:26)
        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:906:3
    make: *** [test] Error 8

这是我要运行的测试:

'use strict';

var assert = require('assert')
  , should = require('should');

var exchangeData = {};

suite('exchange', function() {



test('buy should add a BUY nockmarket order', function(done) {
    exchangeData = exchange.buy(40, 100, exchangeData);
    exchangeData.buys.volumes[40].should.eql(100);
    done();
});


test('sell should add a SELL nockmarket order', function(done) {
  exchangeData = exchange.sell(41, 200, exchangeData);
  exchangeData.sells.volumes['41'].should.eql(200); //this is line 22
  done();
});


test('sell should produce trades', function(done) {
  exchangeData = exchange.sell(40, 75, exchangeData);
  exchangeData.trades[0].price.should.eql(40);
  exchangeData.trades[0].volume.should.eql(75);
  exchangeData.buys.volumes[40].should.eql(25);
  exchangeData.sells.volumes[41].should.eql(200);
  done();
});





});

最佳答案

您的代码中有一些无效字符,如果您使用适当的文本编辑器,您会看到它们。行号有点偏离,但这显然是原因。

这是来自 Sublime Text 的屏幕截图:

enter image description here

\uFFFC,更多信息here .

删掉就可以了(看不到所以把分号到下一个test()全部删掉

关于javascript - 运行 node.js mocha 测试时意外的 token 非法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27758833/

相关文章:

javascript - 在 DigitalOcean 服务器上执行 nodeJS 应用程序

javascript - 使用 ES6 样式导入的 mocha 测试

javascript - 如何在Vue cli中的浏览器后退按钮上渲染分页和内容?

node.js - 用于传感器数据收集的 MongoDB 查询

javascript - 实现 github.com 文件无缝文件导航

jquery - 带环回的文件上传

javascript - 如何测试自己的 mongodb 包装器

javascript - 使用 Mocha 运行测试也会启动主程序

javascript - 正则表达式 - 仅当字符串包含任何其他字符时才允许某些字符

javascript - 使用正则表达式删除分隔符周围的尾随和前导空格