@nestjs/testing
- Version 12.2.0
- Published
- 44.3 kB
- 1 dependency
- MIT license
Install
npm i @nestjs/testingyarn add @nestjs/testingpnpm add @nestjs/testingOverview
Nest - modern, fast, powerful node.js web framework (@testing)
Index
Classes
Interfaces
Type Aliases
Classes
class CapturingLogger
class CapturingLogger extends ConsoleLogger {}A logger for tests that records every log call with its structured data, so that tests can assert on it. Pass it to
setLogger()of the testing module builder, or toapp.useLogger(), to capture the framework's logs and the logs ofLoggerinstances.Every level is captured unless
logLevelsis set; theNEST_LOG_LEVELenvironment variable is ignored.Example 1
const logger = new CapturingLogger(); const moduleRef = await Test.createTestingModule({ providers: [PaymentsService] }) .setLogger(logger) .compile();
await moduleRef.get(PaymentsService).charge(order);
logger.assertLogged({ level: 'warn', context: 'PaymentsService', message: /retrying/ });
constructor
constructor(options?: CapturingLoggerOptions);property entries
readonly entries: CapturedLog[];The recorded entries, oldest first.
method assertLogged
assertLogged: (matcher: CapturedLogMatcher) => CapturedLog;Throws an error listing the captured entries if no entry matches.
Returns
The first entry that matches.
method assertNotLogged
assertNotLogged: (matcher: CapturedLogMatcher) => void;Throws an error listing the matching entries if any entry matches.
method clear
clear: () => void;Removes the recorded entries.
method debug
debug: (message: any, ...optionalParams: any[]) => void;method error
error: (message: any, ...optionalParams: any[]) => void;method fatal
fatal: (message: any, ...optionalParams: any[]) => void;method filter
filter: (matcher?: CapturedLogMatcher) => CapturedLog[];Returns the entries that match.
method find
find: (matcher: CapturedLogMatcher) => CapturedLog | undefined;Returns the first entry that matches.
method log
log: (message: any, ...optionalParams: any[]) => void;method verbose
verbose: (message: any, ...optionalParams: any[]) => void;method warn
warn: (message: any, ...optionalParams: any[]) => void;class Test
class Test {}method createTestingModule
static createTestingModule: ( metadata: ModuleMetadata, options?: TestingModuleOptions) => TestingModuleBuilder;class TestingModule
class TestingModule extends NestApplicationContext {}constructor
constructor( container: NestContainer, graphInspector: GraphInspector, contextModule: Module, applicationConfig: ApplicationConfig, scope?: Type<any>[]);property graphInspector
protected readonly graphInspector: GraphInspector;method createNestApplication
createNestApplication: { <T extends INestApplication = INestApplication>( httpAdapter: HttpServer | AbstractHttpAdapter, options?: NestApplicationOptions ): T; <T extends INestApplication = INestApplication>( options?: NestApplicationOptions ): T;};method createNestMicroservice
createNestMicroservice: <T extends object>( options: NestMicroserviceOptions & T) => INestMicroservice;class TestingModuleBuilder
class TestingModuleBuilder {}constructor
constructor( metadataScanner: MetadataScanner, metadata: ModuleMetadata, options?: TestingModuleOptions);method compile
compile: ( options?: Pick<NestApplicationContextOptions, 'snapshot' | 'preview'>) => Promise<TestingModule>;method overrideFilter
overrideFilter: <T = any>(typeOrToken: T) => OverrideBy;method overrideGuard
overrideGuard: <T = any>(typeOrToken: T) => OverrideBy;method overrideInterceptor
overrideInterceptor: <T = any>(typeOrToken: T) => OverrideBy;method overrideModule
overrideModule: (moduleToOverride: ModuleDefinition) => OverrideModule;method overridePipe
overridePipe: <T = any>(typeOrToken: T) => OverrideBy;method overrideProvider
overrideProvider: <T = any>(typeOrToken: T) => OverrideBy;method setLogger
setLogger: (testingLogger: LoggerService) => this;method useMocker
useMocker: (mocker: MockFactory) => TestingModuleBuilder;Interfaces
interface CapturedLog
interface CapturedLog {}A log call recorded by
CapturingLogger.
property args
args: unknown[];The arguments, as passed to the logger (including the context).
property context
context?: string;The context, e.g. the one passed to
new Logger('Context').
property error
error?: Error;The first
Errorpassed to the call, as the message or after it.
property level
level: LogLevel;property message
message: unknown;The message. A lazy message (a function) is evaluated, and when an
Erroris logged as the message, this is the error's message.
property params
params?: Record<string, any>;The plain objects passed after the message, merged.
property stack
stack?: string;The stack trace passed as a string, as in
logger.error(message, stack).
interface CapturedLogFilter
interface CapturedLogFilter {}Criteria for
CapturingLoggerqueries. Every criterion that is set must match.
property context
context?: string | RegExp;A string matches the context exactly.
property level
level?: LogLevel;property message
message?: string | RegExp;A string matches when the message contains it. Only string messages match (an
Errorlogged as the message counts, through its message).
property params
params?: Record<string, unknown>;Matches when each of these params is deeply equal to the logged one.
interface CapturingLoggerOptions
interface CapturingLoggerOptions extends ConsoleLoggerOptions {}property print
print?: boolean;If enabled, logs are also printed, as a
ConsoleLoggerwith the same options would print them. false
interface OverrideBy
interface OverrideBy {}property useClass
useClass: (metatype: any) => TestingModuleBuilder;property useFactory
useFactory: (options: OverrideByFactoryOptions) => TestingModuleBuilder;property useValue
useValue: (value: any) => TestingModuleBuilder;interface OverrideByFactoryOptions
interface OverrideByFactoryOptions {}Type Aliases
type CapturedLogMatcher
type CapturedLogMatcher = CapturedLogFilter | ((entry: CapturedLog) => boolean);type MockFactory
type MockFactory = (token?: InjectionToken) => any;type TestingModuleOptions
type TestingModuleOptions = Pick< NestApplicationContextOptions, 'moduleIdGeneratorAlgorithm'>;Package Files (8)
Dependencies (1)
Dev Dependencies (0)
No dev dependencies.
Peer Dependencies (4)
Badge
To add a badge like this oneto your package's README, use the codes available below.
You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/@nestjs/testing.
- Markdown[](https://www.jsdocs.io/package/@nestjs/testing)
- HTML<a href="https://www.jsdocs.io/package/@nestjs/testing"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>
- Updated .
Package analyzed in 3577 ms. - Missing or incorrect documentation? Open an issue for this package.
