node.js - 在 Node 下运行基于 Mocha 脚本的测试时出现意外的 '->'

标签 node.js coffeescript mocha.js

我正在尝试在 Windows 下的 Node 上运行 Mocha 。我还决定为什么不加入一些 CoffeeScript 来好玩。

describe 'Array', ->
  describe '#indexOf()', ->
    it 'should return -1 when not present' ->
      [1,2,3].indexOf(4).should.equal -1

问题是我遇到了错误:

C:\Users\ShaneC\AppData\Roaming\npm\node_modules\coffee-script\lib\coffee-script\coffee-script.js:51
      throw err;
            ^
Error: In C:\projects\BowlingKata\test\test.coffee, Parse error on line 3: Unexpected '->'
    at Object.parseError (C:\Users\ShaneC\AppData\Roaming\npm\node_modules\coffee-script\lib\coffee-script\parser.js:477:11)
    at Object.parse (C:\Users\ShaneC\AppData\Roaming\npm\node_modules\coffee-script\lib\coffee-script\parser.js:554:22)
    at C:\Users\ShaneC\AppData\Roaming\npm\node_modules\coffee-script\lib\coffee-script\coffee-script.js:43:20
    at Object..coffee (C:\Users\ShaneC\AppData\Roaming\npm\node_modules\coffee-script\lib\coffee-script\coffee-script.js:19:17)
    at Module.load (module.js:353:31)

这是我的 mocha.opts 文件:

--reporter spec
--ui bdd
-r should
--compilers coffee:coffee-script

关于我可能做错了什么有什么想法吗?我从 http://net.tutsplus.com/tutorials/javascript-ajax/better-coffeescript-testing-with-mocha/ 复制了代码没有人报告任何问题..

最佳答案

假设您正在调用一个函数it,参数“不存在时应返回-1”,然后调用一个函数来检查这一点,您需要用逗号分隔参数:

describe 'Array', ->
  describe '#indexOf()', ->
    it 'should return -1 when not present', ->
      [1,2,3].indexOf(4).should.equal -1

编译为:

describe('Array', function() {
  return describe('#indexOf()', function() {
    return it('should return -1 when not present', function() {
      return [1, 2, 3].indexOf(4).should.equal(-1);
    });
  });
});

关于node.js - 在 Node 下运行基于 Mocha 脚本的测试时出现意外的 '->',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11157989/

相关文章:

javascript - Should.js 在单个属性上链接多个断言

security - Websockets、socket.io、nodejs 和安全性

javascript - 如何防止文件中的 before 和 beforeEach 应用于所有文件中的所有测试?

javascript - 通过 JS WebRTC 在计时器中发送数据在结束前重新加载时崩溃

javascript - Coffeescript one liner 用于创建具有可变键的 hashmap

coffeescript - 与 CoffeeScript 绑定(bind)

javascript - JavaScript 中包含转义序列的正则表达式

javascript - 将 npm 与 | 一起使用时,不会运行或报告任何 mocha 测试参数

javascript - req.send ('null' ) 不是 Node.js mySQl 的函数

node.js - 是否可以禁用/删除 ExpressJS 中特定路由的中间件?