I'm going crazy trying to handle a TimeoutError that I know is coming. Currently, I'm testing the Hidden Layers scenario from UI Testing Playground in Playwright Node.js and I want to see if there's a way to prevent the TimeoutError from causing the test to fail, since that's the expected behavior. I'm still pretty new to automating tests with both Playwright and Typescript.
I've attempted various methods, including having the clickGreenButton()
method intentionally throw the error, but it seems like the expect() function isn't able to catch it at all.
This is the method inside the HiddenLayersPage.ts
:
async clickGreenButton() {
await this.greenButton.click()
}
Here's the code in the spec file that is supposed to verify that the second click won't be successful because the element to be clicked becomes hidden:
await hiddenLayersPage.clickGreenButton();
expect(async () => await hiddenLayersPage.clickGreenButton()).toThrow();