Loading topic
npx vitest from the previous chapter. You should also be comfortable with ES modules, arrow functions, and closures. The examples use toBe, toEqual, and toThrow. The next chapter covers matchers in detail, so here they only c5 min readdescribe and it, as covered in the previous two chapters. It also assumes you are comfortable with ES modules, arrow functions, and JavaScript's equality rules (=== compared with deep comparison).4 min readdescribe, test, and it, and that you know the basic expect matchers and how to test async code with await. You also need Node.js 18 or later, because one example uses the built-in fetch.5 min readdescribe, it, and expect, and that you know how to test promises with await and .rejects. It also assumes you are comfortable with ES modules and async/await. Spying on existing methods (vi.spyOn) and replacing whole modules (`vi.mock4 min readvi.fn and lifecycle hooks. You should be comfortable with toHaveBeenCalledWith, mockImplementation, mockReturnValue, and afterEach. It also assumes you can read ES module syntax and JavaScript classes.5 min readvi.fn, set their behavior with mockReturnValue and mockResolvedValue, and assert on them with toHaveBeenCalledWith. It also assumes you can test async code with await and .resolves/.rejects. Those topics come from 4 min readadd or a validator often needs a dozen checks that differ only in their inputs and expected output. You could copy the same test body twelve times and change the numbers. That works until you need to change the body, and then you edit it twelve times. test.each lets you write the5 min read.only, .skip, and .todo, or you can leave6 min readexpect(add(2, 3)).toBe(5). That works well for small values. It gets tedious for large objects, formatted strings, error messages, or rendered markup, where typing out the expected result is slow and easy to get wrong. A snapshot assertion 5 min readvitest.config.js and can write tests with describe, it, expect, vi.fn, and lifecycle hooks. It also assumes you know basic DOM APIs such as document.createElement, addEventListener, and querySelector.5 min readdescribe/it, lifecycle hooks, vi.fn, vi.spyOn, vi.mock, 5 min read