DEV Community

Discussion on: Writing Your First React Test

Collapse
 
stevetaylor profile image
Steve Taylor

Testing in a fake browser environment is a fool’s errand. Use Jest for unit tests that are actually unit tests. Otherwise, use Mocha in the browser or Cypress. You can’t efficiently diagnose test failures in JSDom and it doesn’t give you the level of assurance you’d get from testing in a real browser.

Collapse
 
halented profile image
Hal Friday

Thanks for the input! Because Jest comes with React, I assumed it was the test framework most widely used. Do you think taking the time to write unit tests in Jest is worth it if you move integration tests to Mocha, or would you write all tests in one framework?

Collapse
 
stevetaylor profile image
Steve Taylor

Having used both Jest and Mocha extensively, I’d move all front-end tests to Mocha and run them in a browser. Having two different test runners is a hassle.