π Learning and exploring Jest, the JavaScript testing framework.
Jest is a delightful JavaScript Testing Framework with a focus on simplicity.
Jest is pervasive. Let's learn it by example.
NOTE: This project was developed on macOS. It is for my own personal use.
Follow these instructions to run the demo test suite.
- Pre-requisite: Node.js
- I used Node.js v18.17.1 which bundles npm 9.6.7
- Install dependencies
-
npm install
-
- Run the test suite
-
npm test
-
I installed Jest, and I'm surprised how many dependencies were installed. I used the following command:
cat package-lock.json | jq '.packages | keys | length'
Which shows that there are 292 packages installed. I think Jest's focus on simplicity must be a form of "reduced code when authoring tests" and not an absolute simplicity from top-to-bottom.
Jest has experimental support for ECMAScript modules (ESM) and this is
because, in part (or mostly?), a feature that Jest relies on in Node.js is itself experimental. Specifically, Jest uses
virtualization features of Node.js, and it looks to me like the ESM variation of this, called vm.Module
is experimental. I would strongly prefer to use modules, but I'm not willing to reach for experimental features in this
project.
General clean-ups, TODOs and things I wish to implement for this project:
- DONE Scaffold the project
- DONE Do something with mocks
- I'm going to make a function that calls GitHub API using axios. This is a real enough example to make for an effective exercise of Jest features.
- Figure out IDE support correctly. I'm using
require('@jest/globals');
and that's helpful but it doesn't work forjest
itself. Also, I don't declare it inpackage.json
. I think I'm getting it from Intellij? - Get leverage. Jest brings a lot of features. If I'm pulling in the complexity, I want to use it. HTML reports? Watch mode? Code coverage? Things I don't know about yet?