-
-
Notifications
You must be signed in to change notification settings - Fork 71
/
components.spec.ts
81 lines (75 loc) · 1.95 KB
/
components.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import { Component } from '@angular/core';
import { NG_VALIDATORS, NG_VALUE_ACCESSOR } from '@angular/forms';
import { MockComponent } from 'ng-mocks';
import coreReflectDirectiveResolve from 'ng-mocks/dist/lib/common/core.reflect.directive-resolve';
@Component({
selector: 'component',
template: '',
})
export class ComponentDefault {}
@Component({
providers: [
{
multi: true,
provide: NG_VALUE_ACCESSOR,
useExisting: ComponentValueAccessor,
},
],
selector: 'component',
template: '',
})
export class ComponentValueAccessor {}
@Component({
providers: [
{
multi: true,
provide: NG_VALIDATORS,
useExisting: ComponentValidator,
},
],
selector: 'component',
template: '',
})
export class ComponentValidator {}
describe('issue-145:components', () => {
it('does not add NG_VALUE_ACCESSOR to components', () => {
const mock = MockComponent(ComponentDefault);
const { providers } = coreReflectDirectiveResolve(mock);
expect(providers).toEqual([
{
provide: ComponentDefault,
useExisting: jasmine.anything(),
},
]);
});
it('adds NG_VALUE_ACCESSOR to components that provide it', () => {
const mock = MockComponent(ComponentValueAccessor);
const { providers } = coreReflectDirectiveResolve(mock);
expect(providers).toEqual([
{
provide: ComponentValueAccessor,
useExisting: jasmine.anything(),
},
{
multi: true,
provide: NG_VALUE_ACCESSOR,
useFactory: jasmine.anything(),
},
]);
});
it('respects NG_VALIDATORS too', () => {
const mock = MockComponent(ComponentValidator);
const { providers } = coreReflectDirectiveResolve(mock);
expect(providers).toEqual([
{
provide: ComponentValidator,
useExisting: jasmine.anything(),
},
{
multi: true,
provide: NG_VALIDATORS,
useFactory: jasmine.anything(),
},
]);
});
});