Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Why is Jasmine used as default instead of Mocha? #117

Closed
paulmillr opened this issue Jul 3, 2012 · 32 comments
Closed

Why is Jasmine used as default instead of Mocha? #117

paulmillr opened this issue Jul 3, 2012 · 32 comments
Milestone

Comments

@paulmillr
Copy link
Contributor

Jasmine is a bloated and has great problems with support. For example, maintainer firstly commented on opened pull request after nine months.

Mocha has very flexible syntax via Chai.js, much more features and cool reporters.

@addyosmani
Copy link
Member

I personally wouldn't mind us switching over to using Mocha. It wouldn't be too difficult, the basic describe and BDD patterns are about the same. One does have to update their assertions to a different interface for async tests but they're similar feature wise.

Some would say Mocha's async interface is more consistent and a little simpler. A con is that Jasmine matchers are easier to read whilst if using Mocha you would probably pair it with Chai to handle assertions. Personally like Jasmine's style a little more as it feels elegant, but again, it comes down to personal preference.

Jasmine pros

  • Arguably more developers have experience with it and are using it in their projects given how long its been around (Also, silly metric but 3.5K watchers vs 1.5K)
  • Easy to find Jasmine tutorials for most MV* frameworks, whilst Mocha is still considered the new kid on the block.
  • Mature (I see as many people using it as QUnit in the wild)

cons

  • Paul is right in that Pivotal aren't responsive to pull requests, though they have made repo changes within < 3 months
  • Bloated?
  • Mocha is in more active development at the moment and it really isn't that much effort to switch over to it. I would say more new projects are using it over Jasmine.

@mklabs
Copy link
Contributor

mklabs commented Jul 3, 2012

FWIW, I kinda like mocha over Jasmine as well.

The BDD ui is pretty much similar to Jasmine, but what makes me prefer mocha is that it works roughly the same to test nodejs and frontend stuff (and as a node developer, this is a huge argument for me in favor to mocha). Plus, as you mentioned, it has some nice features (like the string diff output, test threshold, support for code coverage, etc.) and cool reporters (btw, we use mocha to test the yeoman cli).

We have a pretty good support of Jasmine right now. Even though I'm a fan of Mocha, I'm not sure that switching to Mocha as default is the right thing to do right now (especially for v1, considering the amount of work left).

What I ideally want though is to provide the possibility to user to use their preferred test framework, in some way. I'll certainly be one of the user who will try to use Mocha instead of Jasmine. Generators might help here.

@addyosmani
Copy link
Member

Agreed. IMO, this is a V2 item unless someone is willing to work on an implementation in branch/fork for V1.

@sindresorhus
Copy link
Member

I also prefer Mocha because of the reasons stated above (especially because of the nyancat reporter).

Using generators for this sounds like a good idea.

@addyosmani
Copy link
Member

Side-note, but technically I imagine there are quite a few places in our current architecture that could be replaced with generators. If we're using them for the unit testing solution, does it also make sense to pipe yeoman init back through to a generator too? Just wondering if that would simplify things.

@paulmillr
Copy link
Contributor Author

I'm willing to work on Mocha transfer. Will submit pull in a bit.

@mklabs
Copy link
Contributor

mklabs commented Jul 6, 2012

@paulmillr That would be great! You might want to take a look at https://github.com/mklabs/yeoman/tree/generators/cli/lib/generators/mocha

I did yesterday a few tests on mocha, to see how it goes with generators. I was just playing around with the idea. In the process, I tried to integrate grunt-mocha to be able to run these tests headlessly as we do currently for Jasmine. It may be related to my environment, but I got some issue. kmiyashiro/grunt-mocha#5 is related. It seems to work with this workaround.

@paulmillr
Copy link
Contributor Author

@mklabs 404

@mklabs
Copy link
Contributor

mklabs commented Jul 6, 2012

Ok, I don't know how I can give you access to my fork. I'm guessing it's related to some permission issue. I added the yeoman-preview team, is it the right thing to do? cc @addyosmani

@paulmillr
Copy link
Contributor Author

actually now it seem to work

@addyosmani
Copy link
Member

It should work without special permissions if you're able to view master.
On Jul 6, 2012 12:45 PM, "Paul Miller" <
reply@reply.github.com>
wrote:

actually now it seem to work


Reply to this email directly or view it on GitHub:
#117 (comment)

@addyosmani
Copy link
Member

@paulmillr how are things looking on the Mocha front? :)

@paulmillr
Copy link
Contributor Author

@addyosmani not ready yet, currently busy with doing the same thing to Chaplin, pretty a lot of tests there.

@ghost ghost assigned paulmillr Jul 10, 2012
@paulirish
Copy link
Member

I liked your Mocha PR for Chaplin. The reasons you give for dropping jasmine are sound.
Let's do it

@sindresorhus
Copy link
Member

😄

@paulmillr
Copy link
Contributor Author

i've ran into a support issue with chaplin.

does yeoman need to support ie8? otherwise we won't be able to use awesome chai.js

@addyosmani
Copy link
Member

@paulmillr is it things like this that make ie8 support hard? chaijs/chai#7

@sindresorhus
Copy link
Member

I don't see a reason why we should support oldIE when testing. No decent web dev uses that as their main browser.

@paulmillr
Copy link
Contributor Author

@addyosmani no, it's property descriptors. Getters / setters aren't supported in shitIE, as you know.

@paulmillr
Copy link
Contributor Author

I mean this:

expect(user).to.be.ok

@paulirish
Copy link
Member

Yeoman does not support IE8. We have it documented as supporting IE10 at the moment. I don't expect to change that.

So we're good. 👌

@paulmillr
Copy link
Contributor Author

👍

@addyosmani
Copy link
Member

@paulmillr do you think you might have a chance to put together a PR with the Mocha replacement in the next week or two?

@paulmillr
Copy link
Contributor Author

sure, most likely on this weekend. I've tried to find the place we store default app with jasmine tests, but no chance.

Could anyone point me at it?

@addyosmani
Copy link
Member

When you say the default app, do you mean the app created when you run yeoman init? If so, this is located under lib -> generators -> yeoman -> simpleapp.

@paulmillr
Copy link
Contributor Author

right, thanks

@paulirish
Copy link
Member

@paulmillr if you got time to PR for Mocha we'd love to make moves to it.

@paulmillr
Copy link
Contributor Author

sorry guys, have been buried in brunch / chaplin / work projects.

@addyosmani
Copy link
Member

@paulmillr Do you think you might get a chance to look at this in the next 1-2 weeks? If not, I think it'll probably get shelved for v2.

@paulmillr
Copy link
Contributor Author

@addyosmani #187

@addyosmani
Copy link
Member

@paulmillr Thanks! I'll reply on #187 :)

@mklabs mklabs mentioned this issue Aug 31, 2012
mklabs added a commit to mklabs/yeoman that referenced this issue Aug 31, 2012
and addition of three subtargets app (default), prod (serve dist) and test
(serve test/)

Also updated the way server runs other tasks on start, if the target is "app",
then a new clean coffee compass set of tasks is run, then the watch task is
triggered.

related to yeoman#117. should close yeoman#80, yeoman#206 and yeoman#103

might evolve a bit, need a bit more work / tests
szinya pushed a commit to menthainternet/yeoman that referenced this issue Sep 17, 2014
and addition of three subtargets app (default), prod (serve dist) and test
(serve test/)

Also updated the way server runs other tasks on start, if the target is "app",
then a new clean coffee compass set of tasks is run, then the watch task is
triggered.

related to yeoman#117. should close yeoman#80, yeoman#206 and yeoman#103

might evolve a bit, need a bit more work / tests
mklabs added a commit that referenced this issue Apr 24, 2015
and addition of three subtargets app (default), prod (serve dist) and test
(serve test/)

Also updated the way server runs other tasks on start, if the target is "app",
then a new clean coffee compass set of tasks is run, then the watch task is
triggered.

related to #117. should close #80, #206 and #103

might evolve a bit, need a bit more work / tests
@LechDvorak
Copy link

I think you have a little more flexibility when using Mocha, since you can pick your own assertion library and your own mocking library. This however also comes with a price of a slightly more complex setup and some additional dependencies. Overall I think it depends on each project or your personal preference which of these libraries you want to use. When using Jasmine this does not exclude you from using Sinon. You can still benefit for example from its fake server. Both frameworks are perfectly able to do the job. As of Jasmine 2.x, I think Jasmine is back in the race with Mocha. Interesting thoughts also here https://www.apriorit.com/dev-blog/372-testing-javascript-with-jasmine

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants