Skip to content

Instantly share code, notes, and snippets.

View SebinLee's full-sized avatar

Sebin Lee SebinLee

View GitHub Profile
@SebinLee
SebinLee / card.js
Created May 28, 2020 07:59
React Testing Recipe 번역 - Timer
import React, { useEffect } from "react";
export default function Card(props) {
useEffect(() => {
const timeoutID = setTimeout(() => {
props.onSelect(null);
}, 5000);
return () => {
clearTimeout(timeoutID);
};
@SebinLee
SebinLee / card.test.js
Created May 28, 2020 08:00
React Testing Recipe 번역 - Timer
import React from "react";
import { render, unmountComponentAtNode } from "react-dom";
import { act } from "react-dom/test-utils";
import Card from "./card";
jest.useFakeTimers();
let container = null;
// 가독성을 위해 beforeEach, afterEach는 생략합니다.
@SebinLee
SebinLee / hello.test.js
Created May 28, 2020 08:01
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 부분에 있는 예시코드와 동일합니다.
@SebinLee
SebinLee / multiplerender.test.js
Created May 28, 2020 08:03
React Testing Recipe 번역 - Multiple Renderers
import { act as domAct } from "react-dom/test-utils";
import { act as testAct, create } from "react-test-renderer";
// ...
let root;
domAct(() => {
testAct(() => {
root = create(<App />);
});
});
expect(root).toMatchSnapshot();