I have experience with Jasmine and do like it quite a bit. Does anyone have experience with both Jasmine and Mocha, specifically for Rails? I am wondering if it's worth switching to.
Jasmine was created around 2008. The documentation describes Jasmine as “batteries included,” meaning that it attempts to provide everything a developer needs in a test framework. Mocha is younger than Jasmine, created around 2011. Mocha is not a “complete” test framework, and doesn't attempt to be.
The test finished much faster than Jest, like because there were no variables to handle and no additions to be made. Jasmine is a powerful Javascript testing framework, especially when paired with Angular. Its testing language is a bit more intricate than Jest, which is why it's also great for backend testing.
Jest is a testing platform built on Jasmine, which originated from Facebook. It offers a selection of advanced features that makes testing just a little bit easier. Jasmine provides a clean and simple API for end-to-end JavaScript testing with Node. js or in the browser.
I have done testing in both Jasmine and Mocha. First, switching is relatively easy. The basic describe
and it
BDD pattern is identical. You will need to change how you do your assertions and switch to a different interface for asynchronous tests. Overall they are comparable.
Mocha's asynchronous interface is much simpler and more consistent. Tests and setup can be either synchronous or asynchronous, which is great. This, plus the fact that TJ Holowaychuck is an epic code poet are good reasons to try Mocha.
I do think the Jasmine matchers are easier to read and more elegant, especially when paired with the jasmine-jquery plugin. Mocha is usually paired with a separate library for assertions, often chai.js if you are doing in-browser testing or should.js for node-only testing. I am happy with chai's assert.equal()
interface, but the Jasmine style expect($("#central_errors").html()).toContain("must provide a name");
seems more elegant to me. I am not a fan of the chai.js expect(42).to.be.above(41)
style interface with dot-delimited sentences because it doesn't work well aurally.
Ultimately, this is a personal preference question and I highly encourage you to just spend a day or so writing Mocha tests instead of Jasmine and see how it feels. Totally a worthwhile investment, even if you decide to stick with Jasmine you will be doing so from a place of first-hand knowledge and have an awareness of other ways to solve some of the problems Jasmine solves. I tried it and I'm sticking with Mocha partly because betting on TJ is a good bet, but Jasmine is also a mature, solid, and widely adopted library.
Check out the Teabag project on github. It specifically allows you to use the asset pipeline along with Mocha, Jasmine, or QUnit.
https://github.com/modeset/teaspoon
Mocha's a pretty great library, but I typically use Jasmine -- for me it's primarily about knowledge and experience with Jasmine, but Mocha has some really cool features -- like letting you know when you're bleeding things into the global scope.
Figured it was worth mentioning the project because it specifically allows you to play around with both (in different suites) so you can decide for yourself.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With