当在节点下运行基于摩卡咖啡脚本的testing时,意外的' – >'

我正尝试在Windows下的节点上运行摩卡。 我也决定为什么不扔一些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); }); }); });