Testing in JavaScript

Testing in JavaScript: Your First Tests with Vitest, Testing Edge Cases, Errors and Async Code, Testing a Page with jsdom.

Updated

  1. Your First Tests with Vitest (Journeyman): A unit test is a few lines of code that check one piece of your code and shout when it breaks, and Vitest's describe, it and expect let you write one, run it and read the result.
  2. Testing Edge Cases, Errors and Async Code (Freelancer): Bugs hide at the limits, in the errors and in the code that waits, so this lesson tests all three with Vitest, using toThrow, resolves and rejects, and fake timers that skip ahead in time.
  3. Testing a Page with jsdom (Freelancer): jsdom is a browser without a screen that runs inside your tests, so Vitest can build a little page, click its buttons with dispatchEvent and check what the page says, in a moment and without opening a browser.