Talk a respeito de testes automatizados no frontend (E2E, integração, unitários e visual), dando destaque a aplicações React. A talk foca na utilização da biblioteca react-testing-library desenvolvida por Kent C. Dodds em 2018. Nela, explico o porquê de optarmos por ela, em quais casos ela m...
Talk a respeito de testes automatizados no frontend (E2E, integração, unitários e visual), dando destaque a aplicações React. A talk foca na utilização da biblioteca react-testing-library desenvolvida por Kent C. Dodds em 2018. Nela, explico o porquê de optarmos por ela, em quais casos ela melhor se aplica e dou alguns exemplos de utilização.
Size: 627.74 KB
Language: en
Added: Dec 02, 2018
Slides: 19 pages
Slide Content
REACT TESTING
react-testing-library
AGENDA
●What to test
●Use cases
●Shallow rendering vs. DOM
●react-testing-library (RTL)
●Examples
●Pros
●Cons
●Visual regression tests
WHAT TO TEST*
e2e
Integration
Unit
enzyme ( )
react-testing-library
Shallow
rendering
DOM
VS.
Shallow
rendering
DOM
VS.
Coder User
react-testing-library
●https://github.com/kentcdodds/react-testing-library
●Kent C. Dodds
●Utility functions on top of react-dom and react-dom/test-utils
●DOM testing
“The more your tests resemble the way your software is used, the more
confidence they can give you.”
API
●getByText: Fetches a node by the node’s text content
●getByLabelText: Fetches a node by its corresponding HTML <label/>text.
●getByAltText: Fetches an image node by its alt text
●getByPlaceholderText: Fetches a text input by its placeholder text.
●getByTextId: An “escape hatch” for fetching nodes by its
data-testidattribute in cases where there is no text to fetch by.
dom-testing-library API
●wait
●waitForElement
●fireEvent: Fire DOM events
UTILS
●rerender: this function can be used to update props of the rendered
component
●unmount: This will cause the rendered component to be unmounted
●debug: console.log(prettyDOM(baseElement))
PROS
●Built-in wait command
●API focuses on fetching by visible text on the page
●Also available to React Native
CONS
●Mock is not that simple
●So as test different variations of a page
*Kent C. Dodds appreciation slide*
*WHAT TO TEST
Visual regression testing
●Based in snapshots
●Test what users see
●Code changes doesn’t matter
●Loki, BackstopJS, Diferencify