https://www.theodinproject.com/lessons/node-path-react-new-introduction-to-react-testing
https://www.robinwieruch.de/vitest-react-testing-library/
npm install @testing-library/user-event --save-dev
Now that we have everything we need, let’s briefly go over what some of those packages do. We’ll primarily focus on the @testing-library packages.
-
@testing-library/reactwill give us access to useful functions likerenderwhich we’ll demonstrate later on. -
@testing-library/jest-domincludes some handy custom matchers (assertive functions) liketoBeInTheDocumentand more. (complete list on jest-dom’s github). Jest already has a lot of matchers so this package is not compulsory to use. -
@testing-library/user-eventprovides theuserEventAPI that simulates user interactions with the webpage. Alternatively, we could import thefireEventAPI from@testing-library/react.fireEventis an inferior counterpart touserEventanduserEventshould always be preferred in practice.
https://testing-library.com/docs/dom-testing-library/cheatsheet/