Jest: Add a section on integrating Jest into popular frameworks

Created on 27 Jan 2017  ยท  23Comments  ยท  Source: facebook/jest

While speaking with some devs on a JS meetup I got this feeling, that many of them are struggling with testing JS with specific frameworks like Angular 1.x/2 Ember or Vue.

I think it would be a good idea to find some reliable blog posts on successful integrations with these frameworks and link it from our documentation.

Tutorials on Jest + framework / lib:

  • [x] [Vue.js](https://medium.com/@kentaromiura_the_js_guy/jest-for-all-episode-1-vue-js-d616bccbe186#.d573vrce2)
  • [x] [Angular 1.x](https://medium.com/aya-experience/testing-an-angularjs-app-with-jest-3029a613251#.eyisdnohl)
  • [x] [Angular](https://www.xfive.co/blog/testing-angular-faster-jest/)
  • [ ] Ember โ€“ This is tough, because it runs on QUnit and there's lot of magic going on, but I'll try to revisit this somewhere soon. No luck finding anything relevant in the wild
  • [x] [MobX](https://semaphoreci.com/community/tutorials/how-to-test-react-and-mobx-with-jest)
  • [x] [Redux](http://redux.js.org/docs/recipes/WritingTests.html)
Documentation

Most helpful comment

any lucky with an Ember example? I've tried, but the QUnit looks like a black-box-magic ๐Ÿ˜…

All 23 comments

Here's great @kentaromiura post about Vue.js integration. So good! https://medium.com/@kentaromiura_the_js_guy/jest-for-all-episode-1-vue-js-d616bccbe186#.d573vrce2

+1 for MobX

@thymikee Can I find some reliable blog posts from people using Jest with these frameworks and add them here. Afterwards, I can also make a PR for these tutorial links

@abdulhannanali you're more than welcome!

@thymikee We can include Redux's Documentation part Writing Tests as it prefers Jest for JavaScript Testing. However, It uses enzyme for testing React Components.

any lucky with an Ember example? I've tried, but the QUnit looks like a black-box-magic ๐Ÿ˜…

I've also tried it couple of months ago without luck, but will try to tackle it some time soon, although I'm not so optimistic. We'll see!

Hailing @trentmwillis and @turbo87, who might at least know who else might be interested in exploring this for Ember.

@chriskrycho I am quite interested in this, but since jest only targets nodejs (and jsdom) it doesn't fit well for running frontend tests. In Ember it would need to replace testem+qunit but it seems like the tradeoffs are not worth it at this point.

Actually, this is not true any longer. Jest's runner can now (as of jest@test, Jest 21) run or drive any other test framework (See https://github.com/cpojer/pyjest for running Python tests) and jest-matchers was renamed to expect and will work in browsers. All that's needed is for somebody to hook up the glue code to run a test in a browser.

jest-matchers was renamed to expect and will work in browsers

that part sounds like it could easily be used in Ember tests, just like we integrate Chai (https://github.com/ember-cli/ember-cli-chai)

Jest's runner can now (as of jest@test, Jest 21) run or drive any other test framework

that sounds interesting. the runner is certainly nice to use, but on the other hand I don't see too many advantages of using it for Ember tests at this point. I'd be happy to chat about the details though if anyone is interested in learning about the testing story in Ember and teaching me about Jest and the possible integration points.

@cpojer is it possible to use multiple runners? I would like to integrate ESLint into Jest so that it generates tests per linted file and using a custom runner for that might make this viable, but if only a single runner can be used I would still need to run multiple instances of Jest which defeats the purpose.

@Turbo87 yes, it will be possible. Here is an experimental runner for eslint, by @rogeliog: https://github.com/jest-community/jest-runner-eslint

@thymikee ember-cli-mocha is another popular testing setup in Ember.
A lot of people use mocha through that.

Not sure if that helps you

@brandonjmckay thanks for your interest, but I don't have the bandwidth to tackle Ember integration. Hopefully someone from the community will make it one day :)

Coming from Ember world and Mocha world. My team is looking to move our backend from mocha to jest. Where would I get started if I wanted to begin writing the ember jest integration?

cc @brandonjmckay @thymikee

Are you saying you have something working already? That would be lovely! I remember trying this some time ago and aligning Quint with Jest Jasmine style was a nightmare and I left it as it was not a priority.

If you do have it, feel free to open a PR with the link to the article or repo :)

I do not yet, but I'm interested in taking a stab in the near future!

@thymikee @jasonworden the problem remains the same: Jest does not run in the browser. I would love to see Jest support this use case, but until that is the case using it to properly test Ember apps seems problematic.

while it's true that Jest can drive other test runners it would AFAICT still be responsible for test file discovery and need deep build system integration.

@Turbo87 Is there an existing issue dedicated to running in the browser?

@thymikee FYI Ember has worked towards being test-framework agnostic, and my team is already using it with Mocha, not QUnit! So an Ember-Jest marriage is forseeable ๐Ÿ‘“

@jasonworden @Turbo87 you might like jest-lite which lets you run Jest tests in the browser. ๐Ÿ™‚

Was this page helpful?
0 / 5 - 0 ratings