ng-mocks 13.4.1 → 13.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -39,7 +39,7 @@ The current version of the library **has been tested** and **can be used** with:
39
39
 
40
40
  - [chat on gitter](https://gitter.im/ng-mocks/community)
41
41
  - **[ask a question on Stackoverflow](https://stackoverflow.com/questions/ask?tags=ng-mocks%20angular%20testing%20mocking)**
42
- - [report an issue on GitHub](https://github.com/ike18t/ng-mocks/issues/new)
42
+ - [report an issue on GitHub](https://github.com/ike18t/ng-mocks/issues)
43
43
 
44
44
  ## Very short introduction
45
45
 
@@ -31,12 +31,7 @@ class DependencyComponent implements ControlValueAccessor {
31
31
 
32
32
  @Component({
33
33
  selector: 'tested',
34
- template: `
35
- <app-child
36
- [ngModel]="value"
37
- (ngModelChange)="value = $event"
38
- ></app-child>
39
- `,
34
+ template: ` <app-child [(ngModel)]="value"></app-child> `,
40
35
  })
41
36
  class TestedComponent {
42
37
  public value: any;
@@ -67,9 +62,12 @@ describe('MockForms', () => {
67
62
  MockInstance(DependencyComponent, 'writeValue', writeValue);
68
63
 
69
64
  const fixture = MockRender(TestedComponent);
65
+ // FormsModule needs fixture.whenStable()
66
+ // right after MockRender to install all hooks.
67
+ await fixture.whenStable();
70
68
  const component = fixture.point.componentInstance;
71
69
 
72
- // During initialization it should be called
70
+ // During initialization, it should be called
73
71
  // with null.
74
72
  expect(writeValue).toHaveBeenCalledWith(null);
75
73
 
@@ -77,12 +75,12 @@ describe('MockForms', () => {
77
75
  // and simulate its change, like a user does it.
78
76
  const mockControlEl = ngMocks.find(DependencyComponent);
79
77
  ngMocks.change(mockControlEl, 'foo');
80
- await fixture.whenStable();
81
78
  expect(component.value).toBe('foo');
82
79
 
83
80
  // Let's check that change on existing value
84
81
  // causes calls of `writeValue` on the mock component.
85
82
  component.value = 'bar';
83
+ // Both below are needed to trigger writeValue.
86
84
  fixture.detectChanges();
87
85
  await fixture.whenStable();
88
86
  expect(writeValue).toHaveBeenCalledWith('bar');
@@ -26,9 +26,9 @@ export const EMPTY = new Subject<any>();
26
26
  EMPTY.complete();
27
27
 
28
28
  interface User {
29
- email: string;
30
- firstName: string;
31
- lastName: string;
29
+ email?: string | null;
30
+ firstName?: string | null;
31
+ lastName?: string | null;
32
32
  }
33
33
 
34
34
  @Injectable()
@@ -56,9 +56,9 @@ class StorageService {
56
56
  })
57
57
  class ProfileComponent implements OnInit {
58
58
  public readonly form = new FormGroup({
59
- email: new FormControl(null, Validators.required),
60
- firstName: new FormControl(null, Validators.required),
61
- lastName: new FormControl(null, Validators.required),
59
+ email: new FormControl('', Validators.required),
60
+ firstName: new FormControl('', Validators.required),
61
+ lastName: new FormControl('', Validators.required),
62
62
  });
63
63
 
64
64
  @Input() public readonly profile: User | null = null;
@@ -67,7 +67,7 @@ class ProfileComponent implements OnInit {
67
67
 
68
68
  public ngOnInit(): void {
69
69
  if (this.profile) {
70
- this.form.setValue(this.profile);
70
+ this.form.patchValue(this.profile);
71
71
  }
72
72
  }
73
73
 
@@ -28,9 +28,9 @@ export const EMPTY = new Subject<any>();
28
28
  EMPTY.complete();
29
29
 
30
30
  interface User {
31
- email: string;
32
- firstName: string;
33
- lastName: string;
31
+ email?: string | null;
32
+ firstName?: string | null;
33
+ lastName?: string | null;
34
34
  }
35
35
 
36
36
  @Injectable()
@@ -58,9 +58,9 @@ class StorageService {
58
58
  })
59
59
  class ProfileComponent implements OnInit {
60
60
  public readonly form = new FormGroup({
61
- email: new FormControl(null, Validators.required),
62
- firstName: new FormControl(null, Validators.required),
63
- lastName: new FormControl(null, Validators.required),
61
+ email: new FormControl('', Validators.required),
62
+ firstName: new FormControl('', Validators.required),
63
+ lastName: new FormControl('', Validators.required),
64
64
  });
65
65
 
66
66
  @Input() public readonly profile: User | null = null;
@@ -69,7 +69,7 @@ class ProfileComponent implements OnInit {
69
69
 
70
70
  public ngOnInit(): void {
71
71
  if (this.profile) {
72
- this.form.setValue(this.profile);
72
+ this.form.patchValue(this.profile);
73
73
  }
74
74
  }
75
75