Test component › Alert test
Unable to find an element with the text: alert from hook. This could be because the text is broken up by multiple elements. In this case, you can provide a function for your text matcher to make your matcher more flexible.
<body>
<div>
<ion-app>
<div
class="container"
>
<ion-button
expand="block"
>
Show Alert
</ion-button>
</div>
</ion-app>
</div>
</body>
15 | test("Alert test", async () => {
16 | fireEvent.click(screen.getByText("Show Alert"));
> 17 | await waitFor(()=>{
| ^
18 | expect(screen.getByText("alert from hook")).toBeVisible();
19 | });
20 | })
at waitForWrapper (node_modules/@testing-library/dom/dist/wait-for.js:173:27)
at Object.test (src/components/ExploreContainer.test.tsx:17:9)
Test Suites: 1 failed, 1 passed, 2 total
Tests: 1 failed, 1 passed, 2 total
Snapshots: 0 total
Time: 9.408 s
Thank you very much for your response. I have created a sample project at
You can run dev server using “ionic serve” and click on Show Alert button to display alert. Now run “npm test” to execute test cases. The test case could not find the alert box text.
The particular component and corrosponding test case is available at /src/components directory.
Thanks for the sample project! This appears to be an outstanding issue with the new overlay hooks. Seems that the ionic-react-testing-utils have not been updated to account for them. We currently have a similar issue here