I'm new to coffeescript and I try to create a library for some added syntactic sugar for both cofffeescript and javascript. It uses a lot of decorators, so I'm surprised that this test fails:
it 'sandbox', () ->
id = (x) -> x
fn = (y) -> y == 1
f = id fn
should(f).be.equal(fn)
should(f 3).be.false()
What I think I'm doing:
- create function
id
that returns its first argument. - create function
fn
that returns true iff its first argument is1
- apply
id
onfn
. I expect the resultf
to be exactly the same (reference wise!) asfn
.
should.js says that my result f
isn't even a function:
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)
I am very confused. Is it shouldjs
that does something unexpected, or coffeescript is not being translated to the code I expect it to translate to?