2.12.9 • Published 24 days ago

@nestjs-mod/testing v2.12.9

Weekly downloads
-
License
MIT
Repository
github
Last release
24 days ago

@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

Links

License

MIT

2.12.9

24 days ago

2.12.8

2 months ago

2.12.7

2 months ago

2.12.6

2 months ago

2.12.5

2 months ago

2.12.4

2 months ago

2.12.0

2 months ago

2.12.3

2 months ago

2.12.1

2 months ago

2.12.2

2 months ago

2.11.2

2 months ago

2.11.1

2 months ago

2.11.0

3 months ago

2.10.0

3 months ago

2.9.2

3 months ago

2.9.1

3 months ago

2.9.0

3 months ago

2.7.0

3 months ago

2.8.0

3 months ago

2.6.3

3 months ago

2.6.2

3 months ago

2.6.1

3 months ago

2.6.0

3 months ago

2.5.3

3 months ago

2.5.2

3 months ago

2.5.1

3 months ago

2.5.0

3 months ago

2.3.0

3 months ago

2.2.0

3 months ago

2.4.1

3 months ago

2.4.0

3 months ago

2.3.1

3 months ago

2.0.2

4 months ago

2.1.0

4 months ago

2.0.1

4 months ago

2.0.0

4 months ago

1.10.0

4 months ago

1.9.1

4 months ago

1.9.0

4 months ago

1.8.0

4 months ago

1.9.2

4 months ago

1.7.2

4 months ago

1.7.1

4 months ago

1.7.0

4 months ago

1.6.1

4 months ago

1.6.0

4 months ago

1.5.4

4 months ago

1.5.3

4 months ago

1.5.2

4 months ago

1.5.1

4 months ago

1.5.0

4 months ago

1.4.0

4 months ago

1.3.0

4 months ago

1.2.0

4 months ago

1.1.0

4 months ago

1.0.0

4 months ago