【发布时间】:2015-10-20 17:31:45
【问题描述】:
我是coffeescript 的新手,我尝试为coffeescript 和javascript 添加一些语法糖创建一个库。它使用了很多装饰器,所以我很惊讶这个测试失败了:
it 'sandbox', () ->
id = (x) -> x
fn = (y) -> y == 1
f = id fn
should(f).be.equal(fn)
should(f 3).be.false()
我认为我在做什么:
- 创建函数
id,返回其第一个参数。 - 创建函数
fn,如果它的第一个参数是1,则返回true - 在
fn上申请id。我希望结果f与fn完全相同(参考明智!)。
should.js 说我的结果 f 甚至不是函数:
1) Function guard predicate #bakeFunctionPredicate sandbox:
TypeError: object is not a function
at Context.<anonymous> (/Users/luftzug/private/jspatterns/test/patterns.test.coffee:31:7)
at Test.Runnable.run (/Users/luftzug/private/jspatterns/node_modules/grunt-mocha-cli/node_modules/mocha/lib/runnable.js:221:32)
at Runner.runTest (/Users/luftzug/private/jspatterns/node_modules/grunt-mocha-cli/node_modules/mocha/lib/runner.js:378:10)
at /Users/luftzug/private/jspatterns/node_modules/grunt-mocha-cli/node_modules/mocha/lib/runner.js:456:12
at next (/Users/luftzug/private/jspatterns/node_modules/grunt-mocha-cli/node_modules/mocha/lib/runner.js:303:14)
at /Users/luftzug/private/jspatterns/node_modules/grunt-mocha-cli/node_modules/mocha/lib/runner.js:313:7
at next (/Users/luftzug/private/jspatterns/node_modules/grunt-mocha-cli/node_modules/mocha/lib/runner.js:251:23)
at Immediate._onImmediate (/Users/luftzug/private/jspatterns/node_modules/grunt-mocha-cli/node_modules/mocha/lib/runner.js:280:5)
at processImmediate [as _immediateCallback] (timers.js:367:17)
我很困惑。是shouldjs 做了一些意想不到的事情,还是咖啡脚本没有被翻译成我希望它翻译成的代码?
【问题讨论】:
-
您确定问题出在
f上吗? should.js documentation 注意到be.false在版本 7 中更改为be.false()。也许您还在使用旧版本? -
@andersschuller 在那之前就失败了,所以不,这不是问题(但可能是问题,谁知道)。