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.
  • πŸ”­foundations
    πŸ’Ύdata
    general
    πŸ“forms
    πŸ”auth
    Thank you for the inspiration
    Binalfew πŸš€ 🌌:
    <@105755735731781632> I wanted to thank you for the incredible knowledge I gained from your Epic Web...
    • ❀️1
    1 Β· 2 days ago
  • general
    Welcome to EpicWeb.dev! Say Hello πŸ‘‹
    Kent C. Dodds β—† πŸš€πŸ†πŸŒŒ:
    This is the first post of many hopefully!
    • 18
    81 Β· 2 months ago
  • 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 Β· 2 months 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 Β· 5 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 Β· 6 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 Β· 7 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 Β· 8 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 Β· 9 months ago