Skip to content

Instantly share code, notes, and snippets.

@eunsukimme
Last active June 30, 2021 06:17
Show Gist options
  • Save eunsukimme/0678d986387d01fc9357ba4ddd27c78d to your computer and use it in GitHub Desktop.
Save eunsukimme/0678d986387d01fc9357ba4ddd27c78d to your computer and use it in GitHub Desktop.
test for Counter component with @testing-library/dom
// Counter.test.js
import { getQueriesForElement } from "@testing-library/dom";
import ReactDOM, { unmountComponentAtNode } from "react-dom";
import { act } from "react-dom/test-utils";
import Counter from "./Counter";
let container = null;
beforeEach(() => {
container = document.createElement("div");
document.body.appendChild(container);
});
afterEach(() => {
unmountComponentAtNode(container);
container.remove();
container = null;
});
it("Counter 컴포넌트를 렌더링합니다", () => {
const { getByText } = getQueriesForElement(container);
act(() => {
ReactDOM.render(<Counter />, container);
});
getByText("Counter: 0");
getByText("+");
getByText("-");
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment