๐ Reference
๐ Chapter
Async Methods
fireEvent()
render()
screen()
Queries
TestingLibraryMatcher
Troubleshooting
โฃ
โฃ
๐ฆ Package
@testing-library/dom
@testing-library/jest-dom
@testing-library/react
@testing-library/react-hooks
@testing-library/user-event
React Testing Library
- React Testing Library๋ React๋ฅผ ํ
์คํธํ ์ ์๋ ๋๊ตฌ ์ค์ ํ๋ ์ด๋ค.
- React Testing Library, ์ดํ RTL์ Behavior Driven Test๋ฅผ ์ถ๊ตฌํ๋ ํ
์คํธ ๋ฐฉ๋ฒ์ผ๋ก์จ React ์ปดํฌ๋ํธ์์
prop
, state
๊ฐ ์ด๋ป๊ฒ ๋๋ ์ง์ ๋ํ ํ
์คํธ ๋ฐฉ๋ฒ์ด ์๋๋ค.
- ์ค์ ๋ธ๋ผ์ฐ์ ์์ ๋ณด์ฌ์ง๋ DOM์ ๊ธฐ์ค์ผ๋ก ํ
์คํธ๋ฅผ ์์ฑํ๊ฒ ๋๋ค.
- ์ด ๊ณผ์ ์์์ฒ๋ผ ๋ธ๋ผ์ฐ์ ์์ด ํ
์คํธํ๋ ค๋ ๊ฒฝ์ฐ ์๋ฎฌ๋ ์ด์
๋ DOM์ ์ ๊ณตํ๋ ๊ฒ์ด ํ์ํฉ๋๋ค. ๊ทธ๋์ผ ํ
์คํธ์์ ๋ฒํผ ํด๋ฆญ๊ณผ ๊ฐ์ ์์
์ ํ๊ณ ๋ฒํผ์ ํด๋ฆญํ ํ DOM์ด ์ด๋ค ๋ชจ์ต์ธ์ง ํ์ธํ ์ ์๋ค. ์ด๊ฒ์ด React ํ
์คํ
๋ผ์ด๋ธ๋ฌ๋ฆฌ์ ์ญํ ์ด๋ค.
์ค์น
# NPM
npm i -D jest
npm i -D @testing-libraray/react
npm i -D @testing-library/jest-dom
# YARN
yarn add -D jest
yarn add -D @testing-library/react
yarn add -D @testing-library/jest-dom
input test
- ์ ์ ๊ฐ ์
๋ ฅ ์ฐฝ์ ํ
์คํธ๋ฅผ ํ์ดํํ๋ฉด, ์
๋ ฅํ ๊ฐ๋ค์ด UI์ ๋ํ๋์ผ ํ๋ค.