2

我正在关注一个教程。当我跑步时

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。是否有一些语法错误或一些设置错误?

4

1 回答 1

1

您的问题可能是您的节点版本和 mocha 版本之间不匹配,并且您应该使用该版本。如果您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": ">=0.10.0",
"should": ">=0.5.1"

然后运行npm update解决了问题,测试运行良好。"latest"如果您想锁定它们(分别在我写这篇文章时),"1.3.0"您还可以将这些版本或这些软件包的当前版本设置为。"0.6.3"

于 2012-07-06T16:53:29.493 回答