I'm writing this unit test to verify when clicking back button, then it will show the login page.
The HTML script below is the back button.
<button [routerLink]="[url_sep + login]" class="btn bigBtn btn-gray" keep-width type="button">
Back
</button>
The script below is the unit test which I want to execute.
let de: DebugElement;
let el: HTMLElement;
it('should open login page when click back button', () => {
de = fixture.debugElement.query(By.css('.btn-gray'));
el = de.nativeElement;
el.click();
const compiled = fixture.debugElement.nativeElement;
expect(compiled.querySelector('p').textContent).toContain('Welcome');
});
After I ran this unit test, the button wasn't clicked, because it verified 'Welcome' word in the same page not in the log in page.