我关注tutorial。我跑的时候
require "should"
describe "feature", ->
it "should add two numbers", ->
(2+2).should.equal 4
我跑
mocha routes-test.coffee --compilers coffee:coffee-script
我收到以下错误
1) feature should add two numbers:
AssertionError: expected {} to be true
at Object.true (/home/../../coffeepress/node_modules/should/lib/should.js:251:10)
at Context.<anonymous> (/home/../../coffeepress/test/routes-test.coffee:7:28)
at Test.Runnable.run (/usr/lib/node_modules/mocha/lib/runnable.js:184:32)
at Runner.runTest (/usr/lib/node_modules/mocha/lib/runner.js:300:10)
at Runner.runTests.next (/usr/lib/node_modules/mocha/lib/runner.js:346:12)
at next (/usr/lib/node_modules/mocha/lib/runner.js:228:14)
at Runner.hooks (/usr/lib/node_modules/mocha/lib/runner.js:237:7)
at next (/usr/lib/node_modules/mocha/lib/runner.js:185:23)
at Runner.hook (/usr/lib/node_modules/mocha/lib/runner.js:205:5)
at process.startup.processNextTick.process._tickCallback (node.js:244:9)
这里发生了什么?我安装了should.js(npm install should)和mocha。是否存在语法错误或设置错误?
答案 0 :(得分:1)
您的问题可能是您的节点版本与摩卡版本之间不匹配,您应该使用它。如果您使用了该教程中的package.json
文件,那么您将加载mocha 0.10.0并且应该是0.5.1。当我使用当前版本的节点(v0.8.1)尝试相同的操作时,我在执行npm install
时看到以下警告:
npm WARN engine mocha@0.10.0: wanted: {"node":">= 0.4.x < 0.7.0"} (current: {"node":"0.8.1","npm":"1.1.34"})
npm WARN engine commander@0.5.1: wanted: {"node":">= 0.4.x < 0.7.0"} (current: {"node":"0.8.1","npm":"1.1.34"})
然后当我针对示例测试运行mocha时,你提供了同样的错误。
只需更改我的package.json
中的mocha和版本
"mocha": ">=0.10.0",
"should": ">=0.5.1"
然后运行npm update
解决了问题,测试运行正常。您还可以将这些版本设置为"latest"
或这些软件包的当前版本,如果您想在我写这篇文章时分别将其锁定("1.3.0"
和"0.6.3"
。 / p>