我是coffeescript的新手,我尝试为cofffeescript和javascript添加一些语法糖库。它采用了大量的装饰,让我很惊讶,这个测试失败:为什么shouldjs说这两个对象不一样?
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
- 上
fn
适用id
返回true。我期望结果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
出乎意料,或者coffeescript没有被翻译成我期望它翻译的代码?
你确定这个问题是'F'? [should.js文档](https://github.com/shouldjs/should.js/wiki/Breaking-changes)注意到在版本7中'be.false'变成了'be.false()'。也许你仍在使用旧版本? – andersschuller
@andersschuller在此之前它没有成功,所以不,这不是问题(但可能是一个问题,谁知道)。 – Luftzig