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:
parent
5540fc718a
commit
f60687220b
|
@ -329,14 +329,15 @@ export class FakeComponent {
|
|||
|
||||
export class FakeComponentFactory extends ComponentFactory<any> {
|
||||
componentRef: any = jasmine.createSpyObj(
|
||||
'componentRef', ['instance', 'changeDetectorRef', 'hostView', 'destroy']);
|
||||
|
||||
constructor() {
|
||||
super();
|
||||
this.componentRef.instance = new FakeComponent();
|
||||
this.componentRef.changeDetectorRef =
|
||||
jasmine.createSpyObj('changeDetectorRef', ['detectChanges']);
|
||||
}
|
||||
'componentRef',
|
||||
// Method spies.
|
||||
['destroy'],
|
||||
// Property spies.
|
||||
{
|
||||
changeDetectorRef: jasmine.createSpyObj('changeDetectorRef', ['detectChanges']),
|
||||
hostView: {},
|
||||
instance: new FakeComponent(),
|
||||
});
|
||||
|
||||
get selector(): string {
|
||||
return 'fake-component';
|
||||
|
|
Loading…
Reference in New Issue