MCPcopy
hub / github.com/nestjs/nest / testHelper

Function testHelper

packages/core/test/nest-application-context.spec.ts:15–57  ·  view source on GitHub ↗
(
    injectionKey: InjectionToken,
    scope: Scope,
    additionalProviders: Array<Provider> = [],
  )

Source from the content-addressed store, hash-verified

13 class A {}
14
15 async function testHelper(
16 injectionKey: InjectionToken,
17 scope: Scope,
18 additionalProviders: Array<Provider> = [],
19 ): Promise<NestApplicationContext> {
20 const nestContainer = new NestContainer();
21 const injector = new Injector();
22 const instanceLoader = new InstanceLoader(
23 nestContainer,
24 injector,
25 new GraphInspector(nestContainer),
26 );
27 const { moduleRef } = (await nestContainer.addModule(class T {}, []))!;
28
29 nestContainer.addProvider(
30 {
31 provide: injectionKey,
32 useClass: A,
33 scope,
34 },
35 moduleRef.token,
36 );
37
38 for (const provider of additionalProviders) {
39 nestContainer.addProvider(provider, moduleRef.token);
40 }
41
42 nestContainer.addInjectable(
43 {
44 provide: injectionKey,
45 useClass: A,
46 scope,
47 },
48 moduleRef.token,
49 'interceptor',
50 );
51
52 const modules = nestContainer.getModules();
53 await instanceLoader.createInstancesOfDependencies(modules);
54
55 const applicationContext = new NestApplicationContext(nestContainer);
56 return applicationContext;
57 }
58
59 describe('listenToShutdownSignals', () => {
60 it('shutdown process should not be interrupted by another handler', async () => {

Calls 5

addModuleMethod · 0.95
addProviderMethod · 0.95
addInjectableMethod · 0.95
getModulesMethod · 0.95

Tested by

no test coverage detected