【问题标题】:Mocha Express Coffee should.equal not working摩卡速递咖啡应该等于不工作
【发布时间】:2012-07-06 23:53:54
【问题描述】:

我正在关注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。是语法错误还是设置错误?

【问题讨论】:

    标签: coffeescript express mocha.js


    【解决方案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 时,我得到了同样的错误。

    只需更改 mocha 和我的 package.json 中的版本即可

    "mocha": ">=0.10.0",
    "should": ">=0.5.1"
    

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

    【讨论】:

    • 非常感谢。我知道(有一种感觉)它必须与版本有关。
    猜你喜欢
    • 1970-01-01
    • 2013-05-24
    • 2018-10-31
    • 1970-01-01
    • 2015-12-28
    • 2018-06-27
    • 2018-01-25
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多