Within my Angular application, there exists a straightforward component housing a form inclusive of a text input field.
This input specifically permits strings fewer than 255 characters. In the event that a user types in a string exceeding this limit, an error message is triggered:
https://i.sstatic.net/Yi5xw.png
The following test scenario has been devised:
it('should trigger an error message when the entered description surpasses the character limit', () => {
const inputElement: HTMLInputElement = hostElement.querySelector('.input-element');
inputElement.value = getRandomString(256);
inputElement.dispatchEvent(new Event('input'));
fixture.detectChanges();
const errorElement: HTMLElement = hostElement.querySelector('.error-element');
expect(errorElement).toBeTruthy();
expect(errorElement.innerText).toContain('Please enter no more than 255 characters.');
});
Despite employing fixture.detectChanges()
post the input
event dispatch, and even though the form control status deems as INVALID complete with an error (which I've confirmed through code debugging), the failure to show the error message during the test execution results in failing expectations.