I've migrated my angular 21 tests from jasmine to vitest. And for some of my tests I use separate helper classes (like Page object models). For example:
export class SignUpPageObject {
constructor(fakeVerificationSvc: IUserVerificationService) {
TestBed.overrideProvider(UserVerificationService, { useValue: fakeVerificationSvc });
this.fixture = TestBed.createComponent(IlgSignUpForm);
this.fixture.detectChanges();
this.component = this.fixture.componentInstance;
this.loader = TestbedHarnessEnvironment.loader(this.fixture);
this.docRootLoader = TestbedHarnessEnvironment.documentRootLoader(this.fixture);
}
get emailInput(): Promise<MatInputHarness> {
return this.loader.getHarness(MatInputHarness.with({ label: "Email" }));
}
async getErrorDialog(): Promise<MatDialogHarness> {
const dlgHarnesses = await this.docRootLoader.getAllHarnesses(MatDialogHarness.with({ selector: "#ilgErrorDlg" }));
return dlgHarnesses[0];
}
async getMessageDialog(): Promise<MatDialogHarness> {
const dlgHarnesses = await this.docRootLoader.getAllHarnesses(MatDialogHarness.with({ selector: "#ilgMessageDlg" }));
return dlgHarnesses[0];
}
async clickSendCodeBtn(): Promise<void> {
const sendCodeBtn = await this.sendCodeBtn;
await sendCodeBtn.click();
}
async isSendCodeBtnDisabled(): Promise<boolean> {
return (await this.sendCodeBtn).isDisabled();
}
async emailHasErrors(): Promise<boolean> {
const emailFld = await this.emailFld;
return await emailFld.hasErrors();
}
async getEmailValue(): Promise<string> {
return (await this.emailInput).getValue();
}
// ...
async verificationCodeHasErrors(): Promise<boolean> {
return (await this.verificationCodeFld).hasErrors();
}
async formErrorsCount(): Promise<number> {
const errHarnesses = await this.loader.getAllHarnesses(MatErrorHarness);
for (let errHarness of errHarnesses) {
console.log(await errHarness.getText());
}
return errHarnesses.length;
}
async verificationCodeIsChecked(): Promise<boolean> {
// there should <mat-icon>check</mat-icon> to appear
return (await (await this.verifiedMatIcon).getName()) === "check";
}
readonly component: MyForm;
readonly fixture: ComponentFixture<MyForm>;
private readonly code?: number;
private readonly loader: HarnessLoader;
private readonly docRootLoader: HarnessLoader;
}
The name of this file is page-object.spec.ts. But when I run tests with vitest, I get an error:
No test suite found in file '...\page-object.spec.ts`
How should I name it so by glancing a name it would be clear that this file is part of the tests? Obviously, the *.spec.ts does not work.