2012-06-22 30 views
1

我正嘗試在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/複製的代碼,沒有人有報告任何問題..

回答

2

假設你調用一個函數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); 
    }); 
    }); 
}); 
+0

這裏我忽略WebStorm的錯誤,因爲我不認爲它的理解CofeeSc正確的撕裂..謝天謝地,這是星期五。謝謝! –