How to test nestjs modules?

This page summarizes the projects mentioned and recommended in the original post on /r/Nestjs_framework

Our great sponsors
  • SurveyJS - Open-Source JSON Form Builder to Create Dynamic Forms Right in Your App
  • WorkOS - The modern identity platform for B2B SaaS
  • InfluxDB - Power Real-Time Data Analytics at Scale
  • jest-create-mock-instance

    Create mock instances with Jest

    Create a mock of the Repository that you're testing, it's the simplest one and the more cumbersome one, you can use a library like jest-create-mock-instance or jest-mock-extended or ts-auto-mock to create a mock from typings, but you're responsible to implement how it supposes to work.

  • jest-mock-extended

    Type safe mocking extensions for Jest https://www.npmjs.com/package/jest-mock-extended

    Create a mock of the Repository that you're testing, it's the simplest one and the more cumbersome one, you can use a library like jest-create-mock-instance or jest-mock-extended or ts-auto-mock to create a mock from typings, but you're responsible to implement how it supposes to work.

  • SurveyJS

    Open-Source JSON Form Builder to Create Dynamic Forms Right in Your App. With SurveyJS form UI libraries, you can build and style forms in a fully-integrated drag & drop form builder, render them in your JS app, and store form submission data in any backend, inc. PHP, ASP.NET Core, and Node.js.

  • nest-api-example

    Example of an Restful API with Nest.js and TypeORM

    Example: https://github.com/leosuncin/nest-api-example/blob/88cf73a2189c8556c703a2f8b4ff21970d7ffab4/src/blog/services/comment.service.spec.ts

  • pg-mem

    An in memory postgres DB instance for your unit tests

    In my case, I use TypeORM with PostgreSQL, and there's pg-mem to run an instance in memory, it supports most of the common functionality of PostgreSQL but you will need to do some adjustment to your code to be within the limits.

  • postgres-wasm

    A PostgresQL server running in your browser

    Other in-memory alternatives for PostgreSQL embedded-postgres (I haven't tried it yet) postgres-wasm (currently it only runs in the browser).

  • jest-mongodb

    Jest preset for MongoDB in-memory server

    In the case of MongoDB there's jest-mongodb that use mongodb-memory-server; for other DBMS, I don't know if it's possible to run an instance in memory.

  • WorkOS

    The modern identity platform for B2B SaaS. The APIs are flexible and easy-to-use, supporting authentication, user identity, and complex enterprise features like SSO and SCIM provisioning.

  • mongodb-memory-server

    Spinning up mongod in memory for fast tests. If you run tests in parallel this lib helps to spin up dedicated mongodb servers for every test file in MacOS, *nix, Windows or CI environments (in most cases with zero-config).

    In the case of MongoDB there's jest-mongodb that use mongodb-memory-server; for other DBMS, I don't know if it's possible to run an instance in memory.

  • testcontainers-node

    Testcontainers is a NodeJS library that supports tests, providing lightweight, throwaway instances of common databases, Selenium web browsers, or anything else that can run in a Docker container.

    You can always run a container with a real DB that you can destroy and the re-create whenever you please, use something like docker-compose or testcontainers to run them. Be aware this can be slow and require more resources to implement.

  • nest-graphql-example

    Example of GraphQL with Nest.js and TypeORM

    Example: https://github.com/leosuncin/nest-api-example/blob/master/test/auth.e2e-spec.ts https://github.com/leosuncin/nest-api-example/blob/master/docker-compose.yml https://github.com/leosuncin/nest-auth-example/blob/master/test/todo.e2e-spec.ts

NOTE: The number of mentions on this list indicates mentions on common posts plus user suggested alternatives. Hence, a higher number means a more popular project.

Suggest a related project

Related posts