我正在尝试在 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/