Skip to content
This repository has been archived by the owner on Apr 24, 2020. It is now read-only.

Latest commit

 

History

History
35 lines (25 loc) · 1.18 KB

README.md

File metadata and controls

35 lines (25 loc) · 1.18 KB

Testing with Jest

This project uses Jest as a testing framework.

Run tests

Steps:

  • Make sure to have a (empty) database made for testing only that has its credentials set in .env. See database setup for more info.

  • Run tests:

    # Via test script in package.json
    $ npm run test
    
    # Manually
    $ npx jest
    
    # Just one file (it will search files in the <project_root>/test directory)
    $ npx jest run.controller.e2e-spec.ts
    
    # Also works with wildcards
    $ npx jest run.c*

View coverage report

To view the coverage report in your browser:

$ npm run showcoverage

Database setup

Instead of running tests directly on the database defined in ormconfig.json, tests use a separate database that is defined in .env under the fields starting with 'TEST_DB_'. This ensures that running $ npm run test will never modify the primary database by accident.

Automatic data population

In order to be able to run certain tests, the database will be partially populated automatically. The populate directory contains the migration file that populates the database whenever $ npm run test is run.