1.0.0 • Published 7 months ago

nestjs-mongo-testing v1.0.0

Weekly downloads
-
License
MIT
Repository
-
Last release
7 months ago

NestJS MongoDB testing

A package providing testing utilities for NestJS APIs using MongoDB.

Table of contents

  1. Installation
  2. Documentation

Installation

You can install the package using the following commands:

# yarn
yarn add -D nestjs-mongo-testing

# npm
npm install -d nestjs-mongo-testing

Documentation

Create a test MongoDB database by importing the TestMongooseModule in your test module.

import { TestMongooseModule } from 'nestjs-mongo-testing';

async function setup(): Promise<void> {
  const rootModule: TestingModule = await Test.createTestingModule({
    imports: [TestMongooseModule]
  }).compile();
}

Stop the memory server in your teardown function:

import { MemoryServer } from 'nestjs-mongo-testing';

// Execute this at the end of your test.
async function teardown(): Promise<void> {
  await MemoryServer.getInstance().stop();
}