所以我正在尝试使用用 CoffeeScript 编写的 Mocha 和 Chai 运行单元测试。我知道 Mocha 从 1.0 开始就排除了咖啡脚本,所以我传递了编译器标志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。