Last active
June 30, 2021 06:17
-
-
Save eunsukimme/0678d986387d01fc9357ba4ddd27c78d to your computer and use it in GitHub Desktop.
test for Counter component with @testing-library/dom
This file contains hidden or 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
// 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