Skip to content

Testing

Aleksandr Melnik edited this page Oct 18, 2024 · 3 revisions

Nexus IoC provides a prepared library to simplify container testing.

Usage example:

import { Injectable } from '@nexus-ioc/core';
import { Test } from '@nexus-ioc/testing';

describe('AppModule', () => {
  it('should create instance', async () => {
    @Injectable()
    class AppService {}

    const appModule = await Test.createModule({
      providers: [AppService],
    }).compile();

    const appService = await appModule.get<AppService>(AppService);
    expect(appService).toBeInstanceOf(AppService);
  });
});
Clone this wiki locally