News for hackers. Stuff that matters.
Re:Jest – Painless JavaScript Testing by nlh on Wednesday May 14, 2014 @03:13PM (#7745656)
Sorry for the dumb question, but as a JS (and JS testing) newbie, could someone explain how Jest is different from Jasmine (from which it's built on) or, say, from Mocha?
Re:Jest – Painless JavaScript Testing by vjeux on Wednesday May 14, 2014 @03:20PM (#7745706)
Jasmine provides you with the testing primitives such as describe(), it(), expect(value).toEqual(other): http://facebook.github.io/jest/docs/api.html#globally-inject...

Jest adds multiple layers on-top:

- A mock library (also called stubs) in order to create fake functions and assert that they are called as you want: http://facebook.github.io/jest/docs/mock-functions.html#cont...

- A way to provide an alternate implementation for dependencies using require(): http://facebook.github.io/jest/docs/common-js-testing.html#c...

- It inspects the shape of your dependencies and return a mocked version of them: http://facebook.github.io/jest/docs/automatic-mocking.html#c...

- Finally, it works in node instead of the browser and uses jsdom to let you test code related to the DOM. (It also runs tests in parallel)

Re:Jest – Painless JavaScript Testing by nlh on Wednesday May 14, 2014 @03:50PM (#7745912)
Many thanks! (to both of you ;)
Re:Jest – Painless JavaScript Testing by kumar303 on Thursday May 15, 2014 @12:31PM (#7750482)
Can someone copy/paste this into the docs? :) It was really helpful, thanks.
Re:Jest – Painless JavaScript Testing by jeffmo on Thursday May 15, 2014 @12:54PM (#7750666)
I went ahead and added it to the main page of the website:

http://facebook.github.io/jest/

Re:Jest – Painless JavaScript Testing by jeffmo on Wednesday May 14, 2014 @03:26PM (#7745744)
jinx!
Re:Jest – Painless JavaScript Testing by jeffmo on Wednesday May 14, 2014 @03:25PM (#7745738)
jasmine and mocha are test frameworks (they're the things that supply your describe() and it() functions), but they don't really supply you with everything you need to get set up to run tests.

jest is a test runner that includes a few additional things to try to make all aspects of writing and running tests a little easier...such as:

* Searches for tests to find + execute so that you can put tests near the modules they are testing

* Runs tests in parallel processes so that your test runs finish sooner

* Replace's node's built-in require() function with a custom one that acts almost entirely the same -- except (by default) it returns mocked versions of modules (rather than the real things) when your tests run

* Gives you a fake DOM implementation (using jsdom) so that you can test code that depends on DOM APIs on the command line without having to boot up a browser

Re:Jest – Painless JavaScript Testing by tieTYT on Wednesday May 14, 2014 @05:57PM (#7746675)
Nice. When will there be a grunt plugin for it? I'm using the qunit plugin right now and I notice that it's 10x slower to run than viewing it in the browser. This 10 second feedback loop is driving me crazy.
Re:Jest – Painless JavaScript Testing by jeffmo on Wednesday May 14, 2014 @09:07PM (#7747455)
About a month or three ago I hacked up a grunt task for React, but it wasn't very useful since we hadn't opensourced Jest yet.

The code is now a little stale and dated, but it basically just shells out to the bin/jest.js script included with Jest. Turned out no more than a ~30lines:

https://github.com/jeffmo/react/commit/7a72cbba0eb57844f4e22...

Re:Jest – Painless JavaScript Testing by andwaal on Wednesday May 14, 2014 @06:30PM (#7746845)
Rule number one of Grunt: "If you can npm it, you soon will be able to Grunt it(or Gulp it for that matter)"
Re:Jest – Painless JavaScript Testing by nlh on Wednesday May 14, 2014 @03:49PM (#7745907)
Fantastic. Great answer and now much clearer to me. Thanks! (both of you ;)
Re:Jest – Painless JavaScript Testing by jeffmo on Wednesday May 14, 2014 @04:13PM (#7746075)
BTW, I've updated the main page of the site to give some more context here -- thanks for asking the question!