Skip to content

Commit 60feebc

Browse files
committed
feat: update code for nest v8
1 parent c47c269 commit 60feebc

5 files changed

Lines changed: 17 additions & 11 deletions

File tree

integration/auto-mock/test/bar.service.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,13 @@ describe('Auto-Mocking with token in factory', () => {
3737
providers: [BarService],
3838
})
3939
.useMocker((token) => {
40-
if (token === FooService.name) {
40+
if (token === FooService as any) {
4141
return { foo: sinon.stub };
4242
}
4343
})
4444
.compile();
4545
const service = moduleRef.get(BarService);
46-
const fooServ = moduleRef.get<{ foo: sinon.SinonStub }>('FooService');
46+
const fooServ = moduleRef.get<{ foo: sinon.SinonStub }>(FooService as any);
4747
service.bar();
4848
expect(fooServ.foo.called);
4949
});

packages/core/injector/instance-loader.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ import { InternalCoreModule } from './internal-core-module';
88
import { Module } from './module';
99

1010
export class InstanceLoader {
11-
private readonly injector = new Injector();
11+
protected readonly injector = new Injector();
1212
constructor(
13-
private readonly container: NestContainer,
13+
protected readonly container: NestContainer,
1414
private readonly logger = new Logger(InstanceLoader.name, {
1515
timestamp: true,
1616
}),

packages/testing/testing-injector.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,15 @@ export class TestingInjector extends Injector {
5555
host: moduleRef,
5656
metatype: wrapper.metatype,
5757
});
58-
const internalCoreModule = this.container.getInternalCoreModuleRef() as any;
59-
internalCoreModule._providers.set(name, newWrapper);
60-
internalCoreModule._exports.add(name);
58+
const internalCoreModule = this.container.getInternalCoreModuleRef();
59+
internalCoreModule.addCustomProvider(
60+
{
61+
provide: name,
62+
useValue: mockedInstance,
63+
},
64+
internalCoreModule.providers,
65+
);
66+
internalCoreModule.addExportedProvider(name);
6167
return newWrapper;
6268
} else {
6369
throw err;

packages/testing/testing-instance-loader.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
import { NestContainer } from '@nestjs/core';
21
import { InstanceLoader } from '@nestjs/core/injector/instance-loader';
2+
import { Module } from '@nestjs/core/injector/module';
33
import { MockFactory } from './interfaces';
44
import { TestingInjector } from './testing-injector';
55

66
export class TestingInstanceLoader extends InstanceLoader {
77
protected injector = new TestingInjector();
88

99
async createInstancesOfDependencies(
10-
container?: NestContainer,
10+
modules: Map<string, Module> = this.container.getModules(),
1111
mocker?: MockFactory,
1212
): Promise<void> {
13-
this.injector.setContainer(container);
13+
this.injector.setContainer(this.container);
1414
mocker && this.injector.setMocker(mocker);
1515
await super.createInstancesOfDependencies();
1616
}

packages/testing/testing-module.builder.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ export class TestingModuleBuilder {
6868

6969
this.applyOverloadsMap();
7070
await this.instanceLoader.createInstancesOfDependencies(
71-
this.container,
71+
this.container.getModules(),
7272
this.mocker,
7373
);
7474
this.scanner.applyApplicationProviders();

0 commit comments

Comments
 (0)