- Install jest as a dev dependency
nmp i jest --save-dev
- Create a
test
directory in main project directory - Create a
test/fixtures
directory 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
-i
or--runInBand
options to run tests serially - Add
--watch
to 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