I want to use should.js together with mocha in a Node.js projects which I write in Coffeescript.
In pure Javascript a expression in should.js is like
(function(){
throw new Error('fail');
}).should.throw();
Now I want to write the same expression in Coffeescript. Something like
object.function().should.throw
But that compiles to
object["function"]().should["throw"];
Where is my mistake in my Coffescript code?
I don't know why you write object.function() in your coffeescript. I think the coffeescript to compile to your JS should be:
(->
throw new Error('fail')
).should.throw()
The code I use is
testModel = new DBModel() testModel.get().should.throw()
As far as I can see from the pure-JS-example, you should not invoke the function that you want to test - it's result will likely not have the should method. Use this instead:
testModel = new DBModel();
testModel.get.should.throw();