Merge pull request #16005 from malkovitc/fix/resolve-each-multiple-providers

fix(core): resolve all providers when using resolve() with each option
This commit is contained in:
Kamil Mysliwiec
2025-12-15 10:11:24 +01:00
committed by GitHub
3 changed files with 82 additions and 2 deletions

View File

@@ -24,7 +24,7 @@ describe('Multiple providers under the same token ("each" feature)', () => {
});
});
describe('resolve()', () => {
it('should return an array of providers', async () => {
it('should return an array of request-scoped providers', async () => {
const builder = Test.createTestingModule({
imports: [MultipleProvidersModule],
});
@@ -43,5 +43,25 @@ describe('Multiple providers under the same token ("each" feature)', () => {
expect(multiProviderInstances).to.be.eql(['A', 'B', 'C']);
});
it('should return an array of default-scoped providers', async () => {
const builder = Test.createTestingModule({
imports: [MultipleProvidersModule],
});
const testingModule = await builder.compile();
const multiProviderInstances = await testingModule.resolve<string>(
'MULTI_PROVIDER',
undefined,
{
each: true,
},
);
// @ts-expect-error: make sure "multiProviderInstances" is string[] not string
multiProviderInstances.charAt;
expect(multiProviderInstances).to.be.eql(['A', 'B', 'C']);
});
});
});