Created
August 22, 2023 11:03
-
-
Save textbook/b0512e01728de65d0d8f80250b3223ac to your computer and use it in GitHub Desktop.
Passing test for https://stackoverflow.com/q/76952573/3001761
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, screen } from "@testing-library/react"; | |
import userEvent from "@testing-library/user-event"; | |
import { useState } from "react"; | |
const App = () => { | |
const [count, setCount] = useState(0); | |
return ( | |
<div> | |
<div>{count}</div> | |
<button onClick={() => setCount((c) => c + 1)}>Click me!</button> | |
</div> | |
); | |
}; | |
it("updates the count when the button is clicked", async () => { | |
const user = userEvent.setup(); | |
render(<App />); | |
await user.click(screen.getByRole("button", { name: /click me/i })); | |
await screen.findByText("1"); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment