Created
May 28, 2020 07:50
-
-
Save SebinLee/afeedc0a50663463daf81ca640351e41 to your computer and use it in GitHub Desktop.
React Testing Recipe 번역 - Rendering
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 React from "react"; | |
import { render, unmountComponentAtNode } from "react-dom"; | |
import { act } from "react-dom/test-utils"; | |
import Hello from "./hello"; | |
let container = null; | |
// 가독성을 위해 beforeEach, afterEach는 생략합니다. | |
// 생략된 코드는 위의 Setup/Teardown 부분에 있는 예시코드와 동일합니다. | |
it("renders with or without a name", () => { | |
act(() => { | |
render(<Hello />, container); | |
}); | |
expect(container.textContent).toBe("Hey, stranger"); | |
act(() => { | |
render(<Hello name="Jenny" />, container); | |
}); | |
expect(container.textContent).toBe("Hello, Jenny!"); | |
act(() => { | |
render(<Hello name="Margaret" />, container); | |
}); | |
expect(container.textContent).toBe("Hello, Margaret!"); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment