12 Dec 2012, 16:18
Generic-user-small

christian ehrhardt (1 post)

I definitely got something out of the book so thank you for writing it, however I’d have really liked to have seen a chapter devoted to testing async code and how some of the popular frameworks like Mocha, Jasmine, etc. help make async testing easier.

30 Dec 2012, 22:30
Trevor_burnham__goofy_headshot__pragsmall

Trevor Burnham (51 posts)

I considered writing a chapter on testing, but I don’t have any special insights on the subject. I like Mocha a lot. One interesting thing about it is that an async test in Mocha always has the form

function(done) {
  ...
  done();
}

whereas a synchronous test can be written more simply as

function() {
  ...
}

Mocha does this by testing the arity (length) of the test function: If it takes an argument, then it’s treated as an async test, and Mocha will wait until @done@ is called or fail the test after a timeout. If it doesn’t take an argument, it passes as soon as it returns without an exception.

  You must be logged in to comment