Updating existing tests to use the matcher
In this final section, we’ll use the matcher we’ve just built to simplify the form validation error test suite.
Let’s get started:
- First, register the matcher for our test runs by adding an
import
statement and call toexpect.extend
in thesrc/vitest/registerMatchers.js
file:... import { toBeUnprocessableEntity } from './src/matchers/toBeUnprocessableEntity.js'; ... expect.extend({ toBeUnprocessableEntity });
- Then, in
src/routes/birthdays/page.server.test.js
, find the nesteddescribe
block with the descriptionwhen the name is not provided
. It contains four tests. Leave the first one in place, and replace the last three tests with the following test:describe('when the name is not provided', () => { ... it('does not save the birthday', ...); it('returns a complete error response', () => { ...