2

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?

rotespferd
  • 315
  • 1
  • 5
  • 10

2 Answers2

2

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()
tmaximini
  • 8,403
  • 6
  • 47
  • 69
1

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();
Bergi
  • 630,263
  • 148
  • 957
  • 1,375