@aniya.jaskolski
To test the content of an iframe using Jest, you can use the following steps:
1 2 3 4 5 6 |
import "@testing-library/jest-dom/extend-expect"; test("iframe is present in the document", () => { const iframe = document.querySelector(".iframe-class"); expect(iframe).toBeInTheDocument(); }); |
1 2 3 4 5 6 |
test("content of iframe is correct", () => { const iframe = document.querySelector(".iframe-class"); const iframeDocument = iframe.contentWindow.document; expect(iframeDocument.body.innerHTML).toContain("Expected content"); }); |
1 2 3 4 5 6 7 8 9 |
test("content of iframe is correct", async () => { const iframe = document.querySelector(".iframe-class"); const iframeDocument = iframe.contentWindow.document; // Delay for 1 second to allow content to fully load await new Promise(resolve => setTimeout(resolve, 1000)); expect(iframeDocument.body.innerHTML).toContain("Expected content"); }); |
By following these steps, you can effectively test the content of an iframe using Jest in your unit tests.