2.16.3 • Published 9 months ago

@nestjs-mod/testing v2.16.3

Weekly downloads
-
License
MIT
Repository
github
Last release
9 months ago

@nestjs-mod/testing

Modules and utilities for writing application tests

NPM version monthly downloads Telegram Discord

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.16.3

9 months ago

2.16.1

11 months ago

2.16.2

11 months ago

2.16.0

11 months ago

2.15.0

11 months ago

2.14.1

1 year ago

2.14.2

12 months ago

2.14.0

1 year ago

2.13.4

1 year ago

2.13.2

1 year ago

2.13.3

1 year ago

2.13.0

1 year ago

2.13.1

1 year ago

2.12.10

1 year ago

2.12.9

1 year ago

2.12.8

1 year ago

2.12.7

1 year ago

2.12.6

1 year ago

2.12.5

1 year ago

2.12.4

1 year ago

2.12.0

1 year ago

2.12.3

1 year ago

2.12.1

1 year ago

2.12.2

1 year ago

2.11.2

1 year ago

2.11.1

1 year ago

2.11.0

1 year ago

2.10.0

1 year ago

2.9.2

1 year ago

2.9.1

1 year ago

2.9.0

2 years ago

2.7.0

2 years ago

2.8.0

2 years ago

2.6.3

2 years ago

2.6.2

2 years ago

2.6.1

2 years ago

2.6.0

2 years ago

2.5.3

2 years ago

2.5.2

2 years ago

2.5.1

2 years ago

2.5.0

2 years ago

2.3.0

2 years ago

2.2.0

2 years ago

2.4.1

2 years ago

2.4.0

2 years ago

2.3.1

2 years ago

2.0.2

2 years ago

2.1.0

2 years ago

2.0.1

2 years ago

2.0.0

2 years ago

1.10.0

2 years ago

1.9.1

2 years ago

1.9.0

2 years ago

1.8.0

2 years ago

1.9.2

2 years ago

1.7.2

2 years ago

1.7.1

2 years ago

1.7.0

2 years ago

1.6.1

2 years ago

1.6.0

2 years ago

1.5.4

2 years ago

1.5.3

2 years ago

1.5.2

2 years ago

1.5.1

2 years ago

1.5.0

2 years ago

1.4.0

2 years ago

1.3.0

2 years ago

1.2.0

2 years ago

1.1.0

2 years ago

1.0.0

2 years ago