Socket
Socket
Sign inDemoInstall

@nestjs-mod/testing

Package Overview
Dependencies
4
Maintainers
1
Versions
62
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

@nestjs-mod/testing

Modules and utilities for writing application tests


Version published
Maintainers
1
Created

Readme

Source

@nestjs-mod/testing

Modules and utilities for writing application tests

NPM version monthly downloads Telegram bot

Installation

npm i --save-dev @nestjs/testing @nestjs-mod/testing

Modules

LinkCategoryDescription
DefaultTestNestApplicationCreatesystemDefault test NestJS application creator.
DefaultTestNestApplicationInitializersystemDefault test NestJS application initializer.

Modules descriptions

DefaultTestNestApplicationCreate

Default test NestJS application creator.

Use in NestJS-mod

Use without options.

import { bootstrapNestApplication } from '@nestjs-mod/common';
import { DefaultTestNestApplicationCreate } from '@nestjs-mod/testing';

bootstrapNestApplication({
  modules: {
    system: [DefaultTestNestApplicationCreate.forRoot()],
  },
});

Example of use with override provider.

import { bootstrapNestApplication } from '@nestjs-mod/common';
import { DefaultTestNestApplicationCreate } from '@nestjs-mod/testing';
import { Injectable } from '@nestjs/common';

@Injectable()
export class CatsService {
  findAll() {
    return ['cats'];
  }
}

const fakeCatsService = { findAll: () => ['test'] };

bootstrapNestApplication({
  modules: {
    system: [
      DefaultTestNestApplicationCreate.forRoot({
        staticConfiguration: {
          wrapTestingModuleBuilder: (testingModuleBuilder) =>
            testingModuleBuilder.overrideProvider(CatsService).useValue(fakeCatsService),
        },
      }),
    ],
  },
});
Static configuration
KeyDescriptionConstraintsDefaultValue
wrapTestingModuleBuilderMethod for additional actions with TestingModuleBuilderoptional--
defaultLoggerDefault logger for applicationoptional--

Back to Top


DefaultTestNestApplicationInitializer

Default test NestJS application initializer.

Use in NestJS-mod

Use without options.

import { bootstrapNestApplication } from '@nestjs-mod/common';
import { DefaultTestNestApplicationCreate, DefaultTestNestApplicationInitializer } from '@nestjs-mod/testing';

bootstrapNestApplication({
  modules: {
    system: [DefaultTestNestApplicationCreate.forRoot(), DefaultTestNestApplicationInitializer.forRoot()],
  },
});

An example of getting a provider after running a test application.

import { bootstrapNestApplication } from '@nestjs-mod/common';
import { DefaultTestNestApplicationCreate, DefaultTestNestApplicationInitializer } from '@nestjs-mod/testing';
import { Injectable } from '@nestjs/common';

@Injectable()
export class CatsService {
  findAll() {
    return ['cats'];
  }
}

bootstrapNestApplication({
  modules: {
    system: [
      DefaultTestNestApplicationCreate.forRoot(),
      DefaultTestNestApplicationInitializer.forRoot({
        staticConfiguration: {
          postInit: async ({ app }) => {
            if (app) {
              const catsService = app.get(CatsService);
              console.log(catsService.findAll());
            }
          },
        },
      }),
    ],
  },
});
Static configuration
KeyDescriptionConstraintsDefaultValue
preInitMethod for additional actions before initoptional--
postInitMethod for additional actions after initoptional--
defaultLoggerDefault logger for test applicationoptional--

Back to Top

License

MIT

Keywords

FAQs

Package last updated on 04 May 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc