Skip to content

Commit

Permalink
test(common): improve test suite for getInjectionProviders
Browse files Browse the repository at this point in the history
  • Loading branch information
micalevisk committed Nov 20, 2024
1 parent 5064d9b commit de6f7ca
Showing 1 changed file with 32 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,30 @@ import { getInjectionProviders } from '../../../module-utils/utils/get-injection
describe('getInjectionProviders', () => {
it('should take only required providers', () => {
class C {
static token = 'a';
static token = 'anything';
}
const p: Provider[] = [
class G {
static token = 'anything';
static optional = true;
}
class H {
static token = 'anything';
static optional = false;
}
const providers: Provider[] = [
{
//0
provide: 'a',
useValue: 'a',
},
{
//1
provide: 'b',
useValue: 'b',
},
C,
C, //2
{
//3
provide: 'd',
useFactory: (c, b) => [c, b],
inject: [
Expand All @@ -27,23 +38,36 @@ describe('getInjectionProviders', () => {
optional: true,
},
'x',
G,
H,
],
},
{
//4
provide: 'e',
useFactory: (d, b) => [d, b],
inject: ['d', 'b'],
},
{
//5
provide: 'f',
useValue: 'f',
},
G, //6
H, //7
];

const expected = [
providers[1],
providers[2],
providers[3],
providers[4],
providers[6],
providers[7],
];
// should not include 'a' and 'f'
const expected = p.slice(1, -1);
const result = getInjectionProviders(p, ['e']);
expect(result).to.have.length(expected.length);

const result = getInjectionProviders(providers, ['e']);

expect(result).to.have.members(expected);
expect(result).not.to.have.members([p[0], p[5]]);
});
});

0 comments on commit de6f7ca

Please sign in to comment.