# TestContext Class

Module
import { TestContext } from "@tsed/testing"
Source/packages/testing/src/TestContext.ts

# Overview

class TestContext {
    static get injector(): InjectorService;
    static create(options?: Partial<IDIConfigurationOptions>): Promise<void>;
    static createInjector(options?: any): InjectorService;
    static bootstrap(mod: Type<ServerLoader>, options?: Partial<IDIConfigurationOptions>): () => Promise<void>;
    static reset(): Promise<void>;
    static inject<T>(targets: any[], func: (...args: any[]) => Promise<T> | T): () => Promise<T>;
    static invoke<T = any>(target: TokenProvider, providers: IInvokeOptions[]): T | Promise<T>;
}

# Members

static get injector(): InjectorService

static create(options?: Partial<IDIConfigurationOptions>): Promise<void>

static createInjector(options?: any): InjectorService

Create a new injector with the right default services


static bootstrap(mod: Type<ServerLoader>, options?: Partial<IDIConfigurationOptions>): () => Promise<void>

Load the server silently without listening port and configure it on test profile.


static reset(): Promise<void>

Resets the test injector of the test context, so it won't pollute your next test. Call this in your tearDown logic.


static inject<T>(targets: any[], func: (...args: any[]) => Promise<T> | T): () => Promise<T>

It injects services into the test function where you can alter, spy on, and manipulate them.

The inject function has two parameters

  • an array of Service dependency injection tokens,
  • a test function whose parameters correspond exactly to each item in the injection token array.

static invoke<T = any>(target: TokenProvider, providers: IInvokeOptions[]): T | Promise<T>