Skip to content

Instantly share code, notes, and snippets.

@textbook
Created August 22, 2023 11:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save textbook/b0512e01728de65d0d8f80250b3223ac to your computer and use it in GitHub Desktop.
Save textbook/b0512e01728de65d0d8f80250b3223ac to your computer and use it in GitHub Desktop.
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