From f60687220b9f73cc3bfe183456408533e5f3f7e3 Mon Sep 17 00:00:00 2001 From: George Kalpakas Date: Wed, 4 Nov 2020 20:45:32 +0200 Subject: [PATCH] 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 --- .../test/component-factory-strategy_spec.ts | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/packages/elements/test/component-factory-strategy_spec.ts b/packages/elements/test/component-factory-strategy_spec.ts index 577392fff2..bde7f1f134 100644 --- a/packages/elements/test/component-factory-strategy_spec.ts +++ b/packages/elements/test/component-factory-strategy_spec.ts @@ -329,14 +329,15 @@ export class FakeComponent { export class FakeComponentFactory extends ComponentFactory { 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';