test(elements): simplify creation of `FakeComponentFactory#componentRef` (#39452)

Previously, the `componentRef` property of `FakeComponentFactory` used
in `elements` tests was initialy set to a spy object with all mock
properties defined as spied methods. Later, the properties where
overwritten to the actual mock values.

This commit simplifies the creation of `componentRef` by correctly using
the arguments of [jasmine.createSpyObj()][1] to specify the desired
shape of the spy object (separating spied properties from methods and
directly providing the mock values).

[1]: https://jasmine.github.io/api/3.5/jasmine.html#.createSpyObj

PR Close #39452
This commit is contained in:
George Kalpakas 2020-11-04 20:45:32 +02:00 committed by Misko Hevery
parent 5540fc718a
commit f60687220b
1 changed files with 9 additions and 8 deletions

View File

@ -329,14 +329,15 @@ export class FakeComponent {
export class FakeComponentFactory extends ComponentFactory<any> { export class FakeComponentFactory extends ComponentFactory<any> {
componentRef: any = jasmine.createSpyObj( componentRef: any = jasmine.createSpyObj(
'componentRef', ['instance', 'changeDetectorRef', 'hostView', 'destroy']); 'componentRef',
// Method spies.
constructor() { ['destroy'],
super(); // Property spies.
this.componentRef.instance = new FakeComponent(); {
this.componentRef.changeDetectorRef = changeDetectorRef: jasmine.createSpyObj('changeDetectorRef', ['detectChanges']),
jasmine.createSpyObj('changeDetectorRef', ['detectChanges']); hostView: {},
} instance: new FakeComponent(),
});
get selector(): string { get selector(): string {
return 'fake-component'; return 'fake-component';