Skip to content

Instantly share code, notes, and snippets.

@SebinLee
Created May 28, 2020 08:01
Show Gist options
  • Save SebinLee/c60efd50a30a47f7fb0c03a6de3d0a13 to your computer and use it in GitHub Desktop.
Save SebinLee/c60efd50a30a47f7fb0c03a6de3d0a13 to your computer and use it in GitHub Desktop.
React Testing Recipe 번역 - Snapshot Testing
import React from "react";
import { render, unmountComponentAtNode } from "react-dom";
import { act } from "react-dom/test-utils";
import pretty from "pretty";
import Hello from "./hello";
let container = null;
// 가독성을 위해 beforeEach, afterEach는 생략합니다.
// 생략된 코드는 위의 Setup/Teardown 부분에 있는 예시코드와 동일합니다.
it("should render a greeting", () => {
act(() => {
render(<Hello />, container);
});
expect(
pretty(container.innerHTML)
).toMatchInlineSnapshot(); /* ... gets filled automatically by jest ... */
act(() => {
render(<Hello name="Jenny" />, container);
});
expect(
pretty(container.innerHTML)
).toMatchInlineSnapshot(); /* ... gets filled automatically by jest ... */
act(() => {
render(<Hello name="Margaret" />, container);
});
expect(
pretty(container.innerHTML)
).toMatchInlineSnapshot(); /* ... gets filled automatically by jest ... */
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment