Testing Library

๐Ÿ‘จโ€๐Ÿ’ผ Super! We've got our first UI test. While we already have a way to test some UI stuff with Playwright, it's good for us to be able to test more fine-grained components like this instead of writing a million full-app tests to cover all the edge cases of all our components.
๐Ÿฆ‰ One of the cool things about these lower-level tests is we get to measure how much of our code is run when the tests are running. This can help us direct our efforts to where they're needed most and help us find gaps. You can enable this by using the --coverage flag:
npx vitest --coverage --no-watch
If you run this, it'll output a coverage report to the terminal. It'll also create a coverage folder with a bunch of HTML files in it. If you open coverage/index.html, you'll be shown an interactive report of which lines of code were run and which weren't. You can click on the file names to see the individual files. Try to find the coverage report for the file app/components/forms.tsx. Yikes, that's a lot of red ๐Ÿ˜…
The coverage report consists of four metrics:
  • Statements: The percent of statements that were run (at least once). A statement is a piece of code that performs a specific action, like a function call or a variable declaration.
  • Branches: The percent of branches that were run (at least once). A branch is one part of a conditional statement, like an if statement or a ternary.
  • Functions: The percent of functions that were run (at least once).
  • Lines: The percent of lines that were run (at least once).
There's a bit of overlap in some of these, but altogether they can be combined into a single code coverage score. Read How to know what to test for more on why you should be careful focusing too much on targeting 100% code coverage.
For more on configuring the coverage report, check out the Vitest docs.

๐Ÿงโ€โ™‚๏ธ The rest of the tests will be pretty similar to what you just did, so I'm going to write them for you. Feel free to write them yourself though if you want the extra practice. Here are the test titles to give you an idea:
  • shows a single error
  • shows multiple errors
  • can cope with falsy values
  • adds id to the ul
But there's a problem with these tests I'll need you to work out in the next step.
Login to get access to the exclusive discord channel.
  • general
    npm install everytime I setup a new playground
    Duki ๐ŸŒŒ:
    Is it normal that I have to run `npm install` in my playground directory, everytime I setup the play...
    • โœ…1
    2 ยท 15 days ago
  • general
    Welcome to EpicWeb.dev! Say Hello ๐Ÿ‘‹
    Kent C. Dodds โ—† ๐Ÿš€๐Ÿ†๐ŸŒŒ:
    This is the first post of many hopefully!
    • 18
    81 ยท 8 hours ago
  • general
    Migration to Vite: Server-only module referenced by client
    Fabian ๐ŸŒŒ:
    Hi, I'm working on migrating to Vite following the remix docs (https://remix.run/docs/en/main/guides...
    • โœ…1
    1 ยท 3 months ago
  • general
    Remix Vite Plugin
    Binalfew ๐Ÿš€ ๐ŸŒŒ:
    <@105755735731781632> Now that remix officially supports vite (though not stable) what does it mean...
    • โœ…1
    3 ยท a year ago
  • general
    ๐Ÿ”ญfoundations
    Solutions video on localhost:5639 ?
    quang ๐Ÿš€ ๐ŸŒŒ:
    Hi, so I'm having a hard time navigating (hopefully will be better with time) The nav on epicweb.de...
    • โœ…1
    9 ยท a year ago
  • ๐Ÿงชfull stack testing
    Failing tests in full-stack-testing workshop
    Szabolcs ๐ŸŒŒ:
    I am getting this warning in the testing workshop. ``` Warning: `ReactDOMTestUtils.act` is deprecate...
    • โœ…1
    2 ยท 4 months ago
  • general
    Epicshop is now social and mobile friendly!
    Kent C. Dodds โ—† ๐Ÿš€๐Ÿ†๐ŸŒŒ:
    I'm excited to announce that now the Epic Web workshops are mobile friendly! https://foundations.ep...
    • ๐ŸŽ‰2
    0 ยท 5 months ago
  • ๐Ÿ’พdata
    general
    ๐Ÿ“forms
    ๐Ÿ”ญfoundations
    double underscore?
    trendaaang ๐ŸŒŒ:
    What with the `__note-editor.tsx`? I don't see that in the Remix docs and I don't remember Kent talk...
    • โœ…1
    2 ยท 6 months ago
  • ๐Ÿ”ญfoundations
    ๐Ÿ’พdata
    general
    ๐Ÿ“forms
    ๐Ÿ”auth
    Native Logging
    trendaaang ๐ŸŒŒ:
    I was thinking that it could be useful to log every CRUD operation to help track down errors. Is tha...
    • โœ…1
    6 ยท 7 months ago
  • general
    The video play is pretty laggy currently
    QzCurious ๐ŸŒŒ:
    I thought I should tag you for this <@105755735731781632>. Please take a look if something wrong.
    • โœ…2
    9 ยท 8 months ago
  • general
    New Workshop Scheduled
    Kent C. Dodds โ—† ๐Ÿš€๐Ÿ†๐ŸŒŒ:
    Hey Epic Web devs! I wanted to let you know before everyone else on here: https://www.epicweb.dev/ev...
    • 2
    0 ยท 8 months ago