I tested both jasmine and mocha. Firstly, switching is relatively simple. The basic describe and it BDD template is identical. You will need to change how you make your statements and switch to a different interface for asynchronous tests. In general, they are comparable.
Mocha's asynchronous interface is much simpler and more consistent. Tests and settings can be either synchronous or asynchronous, which is great. This, plus the fact that TJ Holowaychuck is a poet of the epic, is a good reason to try Mocha.
I really think Jasmine matchers are easier to read and more elegant, especially when combined with the jasmine-jquery plugin. Mocha usually bundles with a separate assertion library, often chai.js if you are testing in a browser or should.js for node is just testing. I am pleased with the chai assert.equal() interface, but the Jasmine expect($("#central_errors").html()).toContain("must provide a name"); style expect($("#central_errors").html()).toContain("must provide a name"); seems to me more elegant. I am not a fan of the chai.js expect(42).to.be.above(41) style interface with dot-delimited sentences because it does not work well.
Ultimately, it's a matter of personal preference, and I strongly recommend that you just spend a day or so writing Mocha tests instead of Jasmine and see how it feels. Totally profitable investments, even if you decide to stick to Jasmine, you will do it right away and learn about other ways to solve some of the problems that Jasmine solves. I tried this, and I stick to Mocha partly because betting on TJ is a good bet, but Jasmine is also a mature, solid and widely accepted library.
Peter Lyons Mar 19 '12 at 5:50 2012-03-19 05:50
source share