For testing the image that renders after some time you can do this:
it("shows Loading and then renders the image", async (done) => {
render(<LazyloadImage />);
expect(await screen.findByTestId("fallbackText")).toBeInTheDocument();
expect(
await screen.findByTestId("image", {}, { timeout: 500 })
).toBeInTheDocument();
done();
});
There's something wrong with your custom hook(causing tests to fail), so I removed it from the component but left everything else to render the image after 500ms.
Here's a working sandbox
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…