运行Mocha.js单元测试时编译器中的Coffee Script TypeError

时间:2012-07-03 17:25:58

标签: node.js coffeescript mocha

所以我尝试使用CoffeeScript编写的Mocha和Chai进行单元测试。我知道Mocha从1.0开始就排除了coffeescript所以我传递了编译器标志mocha --compilers coffee:coffee-script。最终发生的事情是,每当我尝试在测试中要求文件时,编译器就会抱怨此错误。否则运行正常。

/usr/local/lib/coffee-script/lib/coffee-script.js:36
      throw err;
            ^
TypeError: In /Users/chietala/workspaces/twl/test/buttonTest.coffee, Array.prototype.indexOf called on null or undefined
    at indexOf (native)
    at Assign.exports.Assign.Assign.isStatement (/usr/local/lib/coffee-script/lib/nodes.js:1147:72)
    at Block.exports.Block.Block.compileNode (/usr/local/lib/coffee-script/lib/nodes.js:262:27)
    at Block.exports.Block.Block.compileWithDeclarations (/usr/local/lib/coffee-script/lib/nodes.js:308:19)
    at Block.exports.Block.Block.compileRoot (/usr/local/lib/coffee-script/lib/nodes.js:282:19)
    at Block.exports.Block.Block.compile (/usr/local/lib/coffee-script/lib/nodes.js:244:21)
    at exports.compile.compile (/usr/local/lib/coffee-script/lib/coffee-script.js:31:51)
    at Object.require.extensions..coffee (/usr/local/lib/coffee-script/lib/coffee-script.js:13:17)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Module.require (module.js:362:17)
    at require (module.js:378:17)
    at /usr/local/lib/node_modules/mocha/bin/_mocha:300:27
    at Array.forEach (native)
    at load (/usr/local/lib/node_modules/mocha/bin/_mocha:297:9)
    at Object.<anonymous> (/usr/local/lib/node_modules/mocha/bin/_mocha:288:1)
    at Module._compile (module.js:449:26)
    at Object.Module._extensions..js (module.js:467:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Module.runMain (module.js:487:10)
    at process.startup.processNextTick.process._tickCallback (node.js:244:9)

我的测试文件中的所有内容如下

  ButtonConsumer = require '../button/base/coffee/ButtonConsumer'

ButtonConsumer看起来像这样。

 class ButtonConsumer
  constructor: ->

目录结构

/
   test
      buttonTest.coffee
   button
      base
        coffee
           ButtonConsumer.coffee

这是相当简单的骨头,这就是为什么我真的很困惑。我正在运行Node v0.8.1,Coffeescript v1.2.0和mocha 1.2.2。

1 个答案:

答案 0 :(得分:0)

Mocha不适用于CoffeeScript 1.2。升级到1.3.3工作正常。