-
-
Notifications
You must be signed in to change notification settings - Fork 7.4k
/
get-injection-providers.util.spec.ts
49 lines (48 loc) 路 1.13 KB
/
get-injection-providers.util.spec.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import { expect } from 'chai';
import { Provider } from '../../../interfaces';
import { getInjectionProviders } from '../../../module-utils/utils/get-injection-providers.util';
describe('getInjectionProviders', () => {
it('should take only required providers', () => {
class C {
static token = 'a';
}
const p: Provider[] = [
{
provide: 'a',
useValue: 'a',
},
{
provide: 'b',
useValue: 'b',
},
C,
{
provide: 'd',
useFactory: (c, b) => [c, b],
inject: [
C,
{
token: 'b',
optional: true,
},
'x',
],
},
{
provide: 'e',
useFactory: (d, b) => [d, b],
inject: ['d', 'b'],
},
{
provide: 'f',
useValue: 'f',
},
];
// should not include 'a' and 'f'
const expected = p.slice(1, -1);
const result = getInjectionProviders(p, ['e']);
expect(result).to.have.length(expected.length);
expect(result).to.have.members(expected);
expect(result).not.to.have.members([p[0], p[5]]);
});
});