Skip to content

Commit 96b2d13

Browse files
Update base.po.ts
1 parent 75b424b commit 96b2d13

1 file changed

Lines changed: 16 additions & 13 deletions

File tree

frontend/src/test/base.po.ts

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,4 @@
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';
92
import { TestbedHarnessEnvironment } from '@angular/cdk/testing/testbed';
103
import { ComponentFixture } from '@angular/core/testing';
114
import { By } from '@angular/platform-browser';
@@ -69,7 +62,6 @@ export abstract class BaseSpecPo<T> {
6962
await this.detectAndWait();
7063
}
7164

72-
7365
text(id: string): string {
7466
return (this.el(id).nativeElement.textContent || '').trim();
7567
}
@@ -101,14 +93,24 @@ export abstract class BaseSpecPo<T> {
10193
* @param options Optional filters to apply.
10294
* @returns A promise that resolves to the harness instance.
10395
*/
96+
harness<H extends ComponentHarness>(harnessType: ComponentHarnessConstructor<H>, options?: BaseHarnessFilters): Promise<H>;
97+
harness<H extends ComponentHarness>(harnessType: HarnessPredicate<H>): Promise<H>;
10498
harness<H extends ComponentHarness>(
105-
harnessType: ComponentHarnessConstructor<H> & { with?: (options?: BaseHarnessFilters) => HarnessPredicate<H> },
99+
harnessType: ComponentHarnessConstructor<H> | HarnessPredicate<H>,
106100
options?: BaseHarnessFilters,
107101
): 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);
110111
}
111-
return this.loader.getHarness(harnessType);
112+
// It's a predicate
113+
return this.loader.getHarness(harnessType as HarnessPredicate<H>);
112114
}
113115

114116
/**
@@ -137,6 +139,7 @@ export abstract class BaseSpecPo<T> {
137139
fix.detectChanges();
138140
await fix.whenStable();
139141
fix.detectChanges(); // Ensure UI is stable after async operations
142+
// biome-ignore lint:correctness/useThisInStatic: dont change this
140143
return new this(fix);
141144
}
142145
}

0 commit comments

Comments
 (0)