我是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