Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript Next Steps with Create React App

Can I use Mocha and Chai as my unit testing with create-react-app?

I do not know much about Jest testing. Can I change that to Mocha and Chai unit testing in create-react-app?

2 Answers

Blake Larson
Blake Larson
13,014 Points

You can change it but it's kind of a hassle. If you want to use Mocha I would probably recommend using webpack instead of create react app. Then you just npm i mocha and set up the test script and it will scrape for your test.js suites. The problem is create-react-app is easier than webpack so it is kind of pick your poison.

You are right it being a hassle. I will have to learn the ways of Jest for now. Maybe down the line I will focus on Webpack too to give myself more flexibility.

I'm pretty sure you can just change that in the package.json

I did try that, but it will not accept mocha commands, even if I use npm run eject command. However you can install chai and use it with jest though by importing it. A bit different but also still familiar enough.

edit- I figured you can use mocha, but you would need to npm run eject , than uninstall jest, along with some folder configuration. Not sure if it is worth it.