NodeJS: Testing with Jest vs Mocha on Typescript in 2021
New year, new me. This is the moment when we as developers run a quick check if our stack is still as good of a decision as it was last year. Since I use Jest and Mocha through most of my day-to-day work, I will only look at those two for today. But, of course, Jasmine and AVA are great options as well.
That being said, let’s set the mood with an ambient stock photo and jump aboard the comparison train!
Setup and Installation
When it comes to getting our libraries up and running inside a Typescript project, both require an extra step, one feeling just slightly less annoying than the other:
Mocha is a bit easier to set up: yarn add mocha @types/mocha --dev
. Then you just install ts-node (which you very likely already have installed) and reference it in mocha’s .mocharc.json
config file:
Jest, however, is best run with ts-jest, which in turn is almost a secondary library. Also they don’t do semver, so be careful on those updates. So go ahead and yarn add jest ts-jest
…