There is a failure in the below case, while the same scenario passes in another location.
it('login labels', () => {
const terms = fixture.nativeElement as HTMLElement;
expect(terms.querySelector('#LoginUsernameLabel')?.textContent).toContain("User ID");
});
HTML
<div class="col-12 row align-items-center hb-login-container" id="Login">
<section class="col-10 offset-1 col-sm-8 offset-sm-2 col-md-6 offset-md-3 col-lg-4 offset-lg-4 hb-login-box"
id="HBLoginBoxSection">
<h1 class="mb-4" id="HBLoginHeading">Login</h1>
<form [formGroup]="loginForm" (ngSubmit)="onSubmit()" class="col-12 p-0 hb-login-form" id="HBLoginForm">
<div class="form-group">
<label for="LoginUsername" class="hb-form-label" id="LoginUsernameLabel" [ngClass]="{
'hb-field-error':
!!f.username.invalid &&
(!!f.username.dirty || !!f.username.touched)
}">User ID</label>
An error is occurring:
TypeError: Cannot read properties of undefined (reading 'nativeElement')
This test case should pass.