|
1 | | -import { |
2 | | - type BaseHarnessFilters, |
3 | | - type ComponentHarness, |
4 | | - type ComponentHarnessConstructor, |
5 | | - type HarnessLoader, |
6 | | - type HarnessPredicate, |
7 | | - TestElement, |
8 | | -} from '@angular/cdk/testing'; |
| 1 | +import { BaseHarnessFilters, type ComponentHarness, type ComponentHarnessConstructor, type HarnessLoader, type HarnessPredicate } from '@angular/cdk/testing'; |
9 | 2 | import { TestbedHarnessEnvironment } from '@angular/cdk/testing/testbed'; |
10 | 3 | import { ComponentFixture } from '@angular/core/testing'; |
11 | 4 | import { By } from '@angular/platform-browser'; |
@@ -69,7 +62,6 @@ export abstract class BaseSpecPo<T> { |
69 | 62 | await this.detectAndWait(); |
70 | 63 | } |
71 | 64 |
|
72 | | - |
73 | 65 | text(id: string): string { |
74 | 66 | return (this.el(id).nativeElement.textContent || '').trim(); |
75 | 67 | } |
@@ -101,14 +93,24 @@ export abstract class BaseSpecPo<T> { |
101 | 93 | * @param options Optional filters to apply. |
102 | 94 | * @returns A promise that resolves to the harness instance. |
103 | 95 | */ |
| 96 | + harness<H extends ComponentHarness>(harnessType: ComponentHarnessConstructor<H>, options?: BaseHarnessFilters): Promise<H>; |
| 97 | + harness<H extends ComponentHarness>(harnessType: HarnessPredicate<H>): Promise<H>; |
104 | 98 | harness<H extends ComponentHarness>( |
105 | | - harnessType: ComponentHarnessConstructor<H> & { with?: (options?: BaseHarnessFilters) => HarnessPredicate<H> }, |
| 99 | + harnessType: ComponentHarnessConstructor<H> | HarnessPredicate<H>, |
106 | 100 | options?: BaseHarnessFilters, |
107 | 101 | ): Promise<H> { |
108 | | - if (options && harnessType.with) { |
109 | | - return this.loader.getHarness(harnessType.with(options)); |
| 102 | + if (typeof harnessType === 'function') { |
| 103 | + // It's a constructor |
| 104 | + const ctor = harnessType as ComponentHarnessConstructor<H> & { |
| 105 | + with?: (options?: BaseHarnessFilters) => HarnessPredicate<H>; |
| 106 | + }; |
| 107 | + if (options && ctor.with) { |
| 108 | + return this.loader.getHarness(ctor.with(options)); |
| 109 | + } |
| 110 | + return this.loader.getHarness(ctor); |
110 | 111 | } |
111 | | - return this.loader.getHarness(harnessType); |
| 112 | + // It's a predicate |
| 113 | + return this.loader.getHarness(harnessType as HarnessPredicate<H>); |
112 | 114 | } |
113 | 115 |
|
114 | 116 | /** |
@@ -137,6 +139,7 @@ export abstract class BaseSpecPo<T> { |
137 | 139 | fix.detectChanges(); |
138 | 140 | await fix.whenStable(); |
139 | 141 | fix.detectChanges(); // Ensure UI is stable after async operations |
| 142 | + // biome-ignore lint:correctness/useThisInStatic: dont change this |
140 | 143 | return new this(fix); |
141 | 144 | } |
142 | 145 | } |
0 commit comments