# Class PlatformTest

Class platform
Module
import { PlatformTest } from "@tsed/common"
Source/packages/common/src/platform-test/components/PlatformTest.ts

# Overview

class PlatformTest extends DITest {
    static platformBuilder: Type<PlatformBuilder>;
    static create(options?: Partial<TsED.Configuration>): Promise<void>;
<span class="token keyword">static</span> <span class="token function">createInjector</span><span class="token punctuation">(</span>settings?<span class="token punctuation">:</span> <span class="token keyword">any</span><span class="token punctuation">)</span><span class="token punctuation">:</span> <a href="/api/di/services/InjectorService.html"><span class="token">InjectorService</span></a><span class="token punctuation">;</span>

<span class="token keyword">static</span> <span class="token function">bootstrap</span><span class="token punctuation">(</span>mod<span class="token punctuation">:</span> <span class="token keyword">any</span><span class="token punctuation">,</span> settings?<span class="token punctuation">:</span> Partial&lt;TsED.<a href="/api/di/decorators/Configuration.html"><span class="token">Configuration</span></a>&gt;<span class="token punctuation">)</span><span class="token punctuation">:</span> <span class="token punctuation">(</span><span class="token punctuation">)</span> =&gt; Promise&lt;<span class="token keyword">void</span>&gt;<span class="token punctuation">;</span>

<span class="token keyword">static</span> inject&lt;T&gt;<span class="token punctuation">(</span>targets<span class="token punctuation">:</span> <span class="token keyword">any</span><span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token punctuation">,</span> func<span class="token punctuation">:</span> <span class="token punctuation">(</span>...args<span class="token punctuation">:</span> <span class="token keyword">any</span><span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token punctuation">)</span> =&gt; Promise&lt;T&gt; | T<span class="token punctuation">)</span><span class="token punctuation">:</span> <span class="token punctuation">(</span><span class="token punctuation">)</span> =&gt; Promise&lt;T&gt;<span class="token punctuation">;</span>

<span class="token keyword">static</span> <span class="token function">callback</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">:</span> <span class="token keyword">any</span><span class="token punctuation">;</span>
<span class="token keyword">static</span> <span class="token function">createRequestContext</span><span class="token punctuation">(</span>options?<span class="token punctuation">:</span> Partial&lt;<a href="/api/common/platform/domain/RequestContextOptions.html"><span class="token">RequestContextOptions</span></a>&gt;<span class="token punctuation">)</span><span class="token punctuation">:</span> <a href="/api/common/platform/domain/PlatformContext.html"><span class="token">PlatformContext</span></a><span class="token punctuation">;</span>

}

# Members

static platformBuilder: Type<PlatformBuilder>;

static create(options?: Partial<TsED.Configuration>): Promise<void>;

static createInjector(settings?: any): InjectorService;

Create a new injector with the right default services


static bootstrap(mod: any, settings?: Partial<TsED.Configuration>): () => Promise<void>;

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


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 callback(): any;

Return the raw application (express or koa). Use this callback with SuperTest.

let request: SuperTest.SuperTest<SuperTest.Test>;
beforeEach(PlatformTest.bootstrap(Server, {
  mount: {
    "/rest": [ProductsController]
  }
}));
beforeEach(() => {
  request = SuperTest(PlatformTest.callback());
});
1
2
3
4
5
6
7
8
9

static createRequestContext(options?: Partial<RequestContextOptions>): PlatformContext;

Other topics