NestJS boilerplate 🎉
Home
  • English
  • Tiếng Việt
GitHub
Home
  • English
  • Tiếng Việt
GitHub
  • Setup & Development
  • Technologies
  • Architecture
  • API
  • Database
  • Security
  • Testing
  • Benchmarking
  • Deployment
  • Troubleshooting
  • FAQ
  • Convention

    • Naming cheatsheet
    • TypeScript Style Guide and Coding Conventions
    • Clean code Typescript
    • Branch conventions
    • Commit conventions
    • Linting & Formatting

Testing

We use Jest for comprehensive unit testing in our NestJS project. Below are the various commands and methods you can use to run tests effectively.


  • Unit Testing
    • Running a Specific Test File
  • Integration Testing
  • End-to-End (E2E) Testing
    • Running End-to-End (e2e) Tests
  • All Tests
    • Running All Tests
    • Running Tests in Watch Mode
    • Running Tests with Coverage
  • Testing in IDE
    • Visual Studio Code

Unit Testing

Running a Specific Test File

To run tests in a specific file, use the following command:

pnpm test path/to/file

# example: pnpm test src/api/auth/auth.controller.spec.ts

Integration Testing

// TODO: Add details on integration testing.

End-to-End (E2E) Testing

Running End-to-End (e2e) Tests

End-to-end tests can be executed using:

pnpm test:e2e

All Tests

Running All Tests

Execute all test cases across the project using:

pnpm test

Running Tests in Watch Mode

For continuous testing, enabling watch mode allows you to re-run tests automatically upon file changes:

pnpm test:watch

Running Tests with Coverage

To generate a code coverage report, use the command:

pnpm test:cov

Testing in IDE

Visual Studio Code

For a seamless testing experience within Visual Studio Code, install the Jest Runner extension. This extension allows you to run tests directly from the test file, streamlining the development process.

Jest Runner
Jest Runner

By following this guide, you can ensure a robust testing workflow, leading to more reliable and maintainable code.

Edit this page
Last Updated:
Contributors: Lâm Ngọc Khương
Prev
Security
Next
Benchmarking