16 ms·
Jest – Painless JavaScript Testing
- polskibus 12y agoResharper added jasmine support in v.7 as far as I remember. I wonder if Jest would work with Resharper out of the box, would be helpful in .NET world to have the Jest runner integrated with VS.
- chenglou 12y agoShorter feedback loop is always great. Running tests in parallel is a non-brainer. Leveraging Jasmine is great too. Glad to see it's not reinventing the wheel! Here's another interesting part, on dependency injection: http://facebook.github.io/jest/docs/common-js-testing.html#content http://facebook.github.io/jest/docs/common-js-testing.html#c...
- caiob 12y agoIt's great that they're improving an existing/familiar tool like Jasmine. Also, I love the way they treat CommonJS modules.
- nawitus 12y agoI would've built Jest on top of Mocha. It's a slightly better testing framework, especially when it comes to async tests.
- joshuacc 12y agoIn what way? Jasmine 2.0 introduced Mocha-style done() for async tests.
- nawitus 12y agoOh, that's great :). That happened after I evaluated Jasmine the last time.
- vjeux 12y agoMock functions are a really powerful tool. They let you test asynchronous functions in an entirely synchronous way. Because of that, Jest doesn't need to provide special support for asynchronous testing http://facebook.github.io/jest/docs/tutorial.html#content http://facebook.github.io/jest/docs/tutorial.html#content
- couchand 12y agoThat might work for simple cases but I'd be worried that switching all your asynchronous calls to synchronous has the potential to introduce bugs that your tests would then miss. Testing asynchronous functions is hard for lots of reasons, and only one of them is that you have to wait for it to finish.
- jeffmo 12y agoAt some point I'd like to add support for using mocha within Jest as well. Right now we use jasmine internally, so I was pretty focused on getting it running with that. However, it is (quite intentionally) built such that the 'jasmine' parts are pretty isolated similar to a plug-in; So it should be possible to build plug-ins for other frameworks like Mocha as well at some point.
- pajtai 12y agoWish all it was was a mocking library... w/o the testing built in. That way you could use it easily with Mocha (and should, etc).
- jeffmo 12y ago(Hi, I'm the fb eng who wrote Jest) Yea, I'd really like to add support for other testing frameworks as well. Right now we use jasmine internally, so I was pretty focused on getting it running with that. However, it is (quite intentionally) built such that the 'jasmine' parts are pretty isolated similar to a plug-in; So it should be possible to build plug-ins for other frameworks as well (like Mocha, QUnit, etc) in the future.
- glenjamin 12y agoThis looks really neat, having to re-specify the interface of the collaborators is generally a bunch of boilerplate you don't want to need! Did you consider building on top of Sinon.JS and only having jest do the require/detect/build-mock part? Your mock API seems very similar.
- jeffmo 12y agoI hadn't looked at Sinon.JS before, but it does seem worth checking into...thanks!
- waterfowl 12y agothis is awesome. thank you for your work.
- skeeterbug 12y agoAny plans to support AMD or just commonjs?
- chadhietala 12y agoYou can use this https://github.com/Jakobo/redefine https://github.com/Jakobo/redefine
- spicyj 12y agoAs someone who's become a React core contributor since React was released a year ago and had the opportunity to work with a handful of people from the Facebook frontend team, I want to say that I'm really impressed with the quality of the JavaScript libraries that Facebook has released. React is the obvious big one, but other smaller projects like regenerator and jstransform are awesome too. I'm excited to see Jest join the party. Congrats guys. :)
- rmrfrmrf 12y agoWow, Facebook has been rocking the house lately with their JS contributions. Great work and thank you!
- nlh 12y agoSorry 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?
- vjeux 12y agoJasmine provides you with the testing primitives such as describe(), it(), expect(value).toEqual(other): http://facebook.github.io/jest/docs/api.html#globally-injected-variables 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#content 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#content 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#content 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)
- elwell 12y agoI wonder if they are using CoffeeScript anywhere at Facebook? http://facebook.github.io/jest/docs/tutorial-coffeescript.html#content http://facebook.github.io/jest/docs/tutorial-coffeescript.ht...
- vjeux 12y agoWe're not using CoffeeScript inside of Facebook. But we are using many ES6 features that make JS look a lot like CoffeeScript such as classes, arrow functions, rest arguments, destructuring assignment ... I figured that CoffeeScript would be a good example to show that Jest supports languages that transpile to JS :)
- skeeterbug 12y agoCurious - What are you using to transpile your ES6? Traceur?
- jeffmo 12y agoInternally we use jstransform (github.com/facebook/jstransform) because it allows us to plug in individual transforms more easily. It's also what React uses for it's jsx transformations. jstransform also ships with a few es6 features out of the box (classes, arrow functions, etc -- and the number is growing!), but Traceur definitely has more.
- deleted 12y ago[deleted]
- jamesgpearce 12y agoActually our recent shortcuts-for-framer project happens to use CoffeeScript, but this is very much an outlier. https://github.com/facebook/shortcuts-for-framer https://github.com/facebook/shortcuts-for-framer
- peteratt 12y agoMight be a silly question, but has anyone tried Jest along with AngularJS and survived to tell the story? Mocking stuff has always been one of my biggest pain points when testing on Angular and I'm really itching to try this! Congrats folks at Facebook.
- rquantz 12y agoAgreed on that count. Have you come up with any good solutions for angular? I always feel like my tests end up with too much boilerplate.
- camus2 12y agoExplain me how mocking is difficult with Angular? when Angular has a mocking framework.
- peteratt 12y agoWhere did I say "difficult"? I said "pain point", which is different. In my experience, same as your sibling comment, you end up having a lot of boilerplate and it's just convoluted. Mocking out stuff should be simpler, in my opinion. How about auto-generating Jasmine spies, for example?
- yazaddaruvala 12y agoIs it just me, or does having the background tinted red make you anxious too?
- spicyj 12y agoI toned it down a little bit -- hope that helps. :)
- saraid216 12y agoWhat it really needs is a GIF of Harley Quinn dancing in the background. (This is a joke. Please don't do it.)
- yazaddaruvala 12y agoYeah it does. Thanks
- etrinh 12y agoThis looks cool. Manual mocking has always been, if not a pain, a major annoyance. On a side note, I got a good chuckle from the "Bobby Tables" XKCD reference[1] in the Jest tutorial[2]. [1]: http://xkcd.com/327/ http://xkcd.com/327/ [2]: http://facebook.github.io/jest/docs/tutorial.html http://facebook.github.io/jest/docs/tutorial.html
- camus2 12y agoI think auto mocking modules is the most horrible trick a testing framework can pull. So because you're too lazy to write modules with a minimum of sane dependency injection,you hack require (which is not dependency injection) to mock dependencies? This is actually the most awfull anti pattern i've seen in javascript land yet.Unfortunatly, it's becoming the "way to go" for most developpers. Instead of making your modules pluggable and decoupled,you negates everything testing is for,you just dont write testable code.
- oldmanjay 12y agowhat is the effective difference between mocking an injected dependency and a located one?
- ericclemmons 12y agoThis isn't so bad. Before DI got popular in PHP via Symfony2, we used Zend_Registry. "require" is pretty much the same thing in this context.
- Cthulhu_ 12y agoLooks interesting: the test suite for our current AngularJS project is slowly slowing down, in part because there's just more tests, but the major performance bottlenecks are: * No parallelisation, even if test suites are all independent * DOM tests, which cause a lot of GC pauses * (probably) PhantomJS startup and initialisation (not measured) I've done a simple optimization where my tests get split in the middle and run in two separate terminals (during development, continuous testing), but it's kinda iffy.