from Hacker News

Jest – Painless JavaScript Testing

by huan9huan on 12/8/16, 3:13 AM with 61 comments

  • by orta on 12/8/16, 10:20 AM

    I'm a big fan of Jest - if you're using Jest with Visual Studios Code, I'd recommend looking at my extension that gives you a mode IDE-like experience.

    https://github.com/orta/vscode-jest

  • by rileyt on 12/8/16, 5:47 AM

    Jest used to have a lot of problems and was poorly maintained.

    Over the past few months, that has changed entirely. Improved speed, lots of bug fixes, snapshot tests and general ease of setup with React projects have all really helped.

    Jest is now the test framework I would suggest for anyone starting a new React project.

  • by wwalser on 12/8/16, 4:59 AM

    I have a strange history with JS test libraries. Of the 4 that I've used, I've fixed bugs in 3 of them within a week of first picking it up. QUnit, Sinon and Jest.

    This isn't commentary on the quality of Jest. After turning off auto-mocking and instead only using the mocking when I really needed it, I ended up using it for a moderately successful side project and enjoyed the experience.

  • by jcoffland on 12/8/16, 7:12 AM

    There's no such thing as painless testing.
  • by haney on 12/8/16, 4:38 AM

    I've been working on a React Native project and I really enjoy how easy jest is to use. It's hard to tell from this post though, is there something new/specific about it? Or are we all just agreeing that it's awesome?
  • by franciscop on 12/8/16, 4:09 PM

    I just migrated a project[1] to Jest. Now I totally think that Jest is AWESOME.

    Before I was mangling with Grunt and PhantomJS, but due to PhantomJS version being back ages I couldn't really test ES6 so I had to do a hybrid and running mocha in an actual browser, and the rest of the dev stack in grunt. Now I am able to do it all automatically. Not only that, but jest includes a browser by default which supports ES6 and an assertion library, so just with 'jest' I am doing the same that I did before with mocha, chai and PhantomJS (+ the pain of installing PhantomJS separately).

    I am not so much into React, but I just fell in love with Jest. Testing will be something totally different from now on, thank you Facebook.

    [1] http://github.com/franciscop/superdom.js

    PS, it was a bit more difficult to integrate Jest into Grunt and I get it without the colors, but I'm sure I'll find a solution soon-ish.

  • by wildpeaks on 12/8/16, 6:05 AM

    Jest sounds good on paper, it's great it exists and it definitely has potential and even improved a lot recently (and I usually try every new version that come up), however I have two pain points with it that prevent me from switching to Jest for now:

    - it uses regexes instead of globs, so you can't just give it the list of tests like you would with Mocha or electron-mocha (e.g. something like "jest src/* * /*.tests.js")

    - it excludes paths that include "node_modules" and it's not just a default (which would be fine), it's hardcoded, so you can forget about local modules, or dependencies that use local modules

    Fortunately, there are already open issues for both, so that might improve in the future :)

    ---

    Edit: I had to add extra spaces in the glob example (so it's slightly incorrect) because HN formatting seems to prevent using "double star".

  • by BJanecke on 12/8/16, 1:23 PM

    This might be a bit frivolous.

    But

    Jest has gotten a whole lot better over the last few months. It used to be slow, cryptic and dogmatic. Now it's fast, transparent and open to debate.

    Great job Jest team!

    I would qualify that but I started this comment saying it was going to be frivolous. If enough people care however I'll expand on this.

  • by misiti3780 on 12/8/16, 4:30 AM

    I have used jest and i have used mocha. I use mocha because I got sick of having to "unmock" everything in jest tests. People have complained that jest is slow, that was never a problem I encountered.

    The unmock becomes very annoying after a while.

  • by spraak on 12/8/16, 12:20 PM

    Two questions:

    1. What good books (or repos) that use JS can you recommend for writing good tests?

    2. What advantages does Jest have over Jasmine?

  • by CoryG89 on 12/8/16, 12:56 PM

    We use usually use a mocha/chai/sinon combo for our testing. Can anyone that has used this make a comparison with that?

    Looks like jest tries to cover all three.

  • by batmansmk on 12/8/16, 5:29 AM

    The last versions are for us better than the other tool. The snapshot feature is pretty neat.
  • by efrafa on 12/8/16, 6:40 AM

    Are you forced to use expect().to... or you can plugin any assert library ? (I get the benefits of expect but I still prefer assert style)
  • by petetnt on 12/8/16, 7:34 AM

    Jest has taken great steps forward in the oast year and I see the momentum only going up. Kudos to the whole team!
  • by kybernetikos on 12/8/16, 11:14 AM

    Snapshot testing overconstrains your tests, and encourages people who see tests breaking just to rerun the snapshot without thinking too much.

    The painlessness comes with a cost.

  • by Nitramp on 12/8/16, 5:07 AM

    This doesn't do browser testing (like Karma), it's just an alternative to mocha, right?
  • by aikah on 12/8/16, 9:17 AM

    Still sticking to Jasmine. Simple and efficient and no need for nodejs to run tests.
  • by krrkrrmjao on 12/8/16, 11:40 AM

    do we really need MORE testing frameworks? the devs should join jasmine instead
  • by gondo on 12/8/16, 12:50 PM

    i'm surprised this does not use Yarn