~/talk

React Hooks broke my tests, now what?

Talkat reactjsday 2020 · on Thursday, 2020-10-15· [testing, react]
slides:none on file

Migration from classes to hooks leaves the app working but half the tests fail because tests assert implementation details like state or internal props. The fix is concrete: migrate tests from Enzyme to React Testing Library + user-event, use render/getBy/queryBy/findBy/waitFor/within/screen, prefer accessible queries, use testing playground and the RTL ESLint plugin, and rely on waitForElementToBeRemoved and user-event for realistic interactions. After migrating, tests survive refactors and accessibility improves.

AI-written summary · about

  1. 0:00Start
  2. 1:53Who am I?
  3. 2:23What is this talk about?
  4. 3:36Why hooks?
  5. 5:07Migrating our codebase to React Hooks
  6. 7:50Why migrate from Enzyme?
  7. 9:58React Testing Library
  8. 11:08Render
  9. 11:46Queries Variants
  10. 16:30Semantic Queries Make use of HTMLS and ARIA compliant selectors
  11. 20:57Firing Events
  12. 22:58Async Utilities
  13. 24:25Helpers
  14. 26:59Common mistakes
  15. 28:18Using getBy with expect .not.toBeInThe Document
  16. 28:55Using await with fireEvent or non async queries
  17. 29:38Using await waitfor()
  18. 30:15Using cleanup
  19. 30:40Using wait For with synchronous queries
  20. 31:01eslint-plugin-testing-library
~/search
type to search 6,249 conferences, 138,987 speakers and 185,172 talks
~/help
cmdctrl k
search every conference, speaker and series
/
focus the filter search
h
home
c
conferences
s
speakers
e
series
t
light / dark — the status bar button does the same
?
this help
esc
close this, then clear every filter — or just the search, while you are typing in it

Ignored while you are typing. Pages without a filter rail have no search to focus.