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 trialmk37
10,271 PointsCan 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
13,014 PointsYou 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.
Zimri Leijen
11,835 PointsI'm pretty sure you can just change that in the package.json
mk37
10,271 PointsI 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.
mk37
10,271 Pointsmk37
10,271 PointsYou 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.