-
-
Notifications
You must be signed in to change notification settings - Fork 71
/
test.spec.ts
53 lines (46 loc) · 1.37 KB
/
test.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
import { Component, NgModule } from '@angular/core';
import {
FormControl,
FormsModule,
ReactiveFormsModule,
} from '@angular/forms';
import { MatInputModule } from '@angular/material/input';
import { MockBuilder, MockRender, ngMocks } from 'ng-mocks';
@Component({
selector: 'target',
template: `
<input
type="text"
matInput
[formControl]="control"
name="form-control"
/>
<input type="text" matInput [(ngModel)]="value" name="ng-model" />
`,
})
class TargetComponent {
public readonly control = new FormControl();
public value;
}
@NgModule({
declarations: [TargetComponent],
imports: [FormsModule, ReactiveFormsModule, MatInputModule],
})
class TargetModule {}
describe('mat-input', () => {
describe('real', () => {
beforeEach(() => MockBuilder(TargetComponent).keep(TargetModule));
it('changes values', () => {
const component = MockRender(TargetComponent).point
.componentInstance;
const input1 = ngMocks.find(['name', 'form-control']);
const input2 = ngMocks.find(['name', 'ng-model']);
ngMocks.change(input1, 'input1');
expect(component.control.value).toEqual('input1');
ngMocks.change(input2, 'input2');
expect(component.value).toEqual('input2');
ngMocks.output(input2, 'ngModelChange').emit('input3');
expect(component.value).toEqual('input3');
});
});
});