- Install jest as a dev dependency
nmp i jest --save-dev
- Create a
testdirectory in main project directory - Create a
test/fixturesdirectory for static content, db connection, etc - Create a
test/__mocks__directory for mocked classes
- Add a start script in package.json
"test": "jest"
- Use env-cmd module to load tests with necessary .env variables
- Add
-ior--runInBandoptions to run tests serially - Add
--watchto watch files for changes and rerun tests related to changed files.
"test": "env-cmd -f ./test.env jest --runInBand --watch"
- Add root property to package.json for jest config
"test": "env-cmd -f ./test.env jest --runInBand --watch",
"jest": {
"testEnvironment": "node"
}
- Install supertest as a dev dependency
npm install supertest --save-dev