Created
February 22, 2021 04:18
-
-
Save rohanBagchi/3ed43263738fb24ef0f70f726b9ba111 to your computer and use it in GitHub Desktop.
devto-testing rtl test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { render, fireEvent, screen } from "@testing-library/react"; | |
import { rest } from "msw"; | |
import { setupServer } from "msw/node"; | |
import App from "./App"; | |
const joke = 'Foo Bar!'; | |
const server = setupServer( | |
rest.get("https://api.icndb.com/jokes/random", (req, res, ctx) => { | |
return res( | |
ctx.json({ | |
type: "success", | |
value: { | |
joke | |
} | |
}) | |
); | |
}) | |
); | |
beforeAll(() => server.listen()); | |
afterEach(() => server.resetHandlers()); | |
afterAll(() => server.close()); | |
test("App", async () => { | |
render(<App />); | |
fireEvent.click(screen.getByText("Get a random joke")); | |
expect(await screen.findByText(joke)).toBeDefined(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment