运行node.js摩卡测试时出现意外令牌ILLEGAL [英] Unexpected token ILLEGAL while running node.js mocha test

查看:129
本文介绍了运行node.js摩卡测试时出现意外令牌ILLEGAL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我搜索了所有内容,但没有弄清楚我在做什么错.我正在尝试设置摩卡咖啡以测试node.js javascript应用程序文件.我已经安装了节点,并已在其上成功运行了一些基本的操作以确认其正常运行.

I have searched all over but have not figured out what I am doing wrong. I am trying to set up mocha for testing node.js javascript application files. I have node installed and have successfully ran basic things on it to confirm it is working.

我在项目文件中安装了mocha,并且在项目文件中也有一个Makefile和一个名为"test"的文件.

I installed mocha in my project file, and also have a Makefile and a file called "test" within my project file as well.

这是我运行命令"make test"时终端(osx 10)吐出的错误.

Here is the error my terminal(osx 10) is spitting out when I run the command "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();
});





});

推荐答案

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

There are some invalid characters in your code, if you used proper text editor, you'd see them. The line numbering is a bit off, but this is clearly the cause.

以下是Sublime Text的屏幕截图:

Here's a screenshot from Sublime Text:

它是\uFFFC,更多信息此处.

只需删除它们(看不到它们,因此将所有内容从分号删除到下一个test().

Just delete them (they can't be seen, so delete all from the semicolon to the next test().

这篇关于运行node.js摩卡测试时出现意外令牌ILLEGAL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆