Adding a Playwright test for validating form errors
In this section we’ll write another Playwright test and then do some up-front planning for the Vitest unit tests we’ll need.
Here’s the next end-to-end test, which you can now add to tests/birthdays.test.js
. It fills in the birthday form, just as in the previous chapter, but this time, the Date of birth field value is invalid
: it is, literally, the word invalid
, which is not a valid date of birth:
test('does not save a birthday if there are validation errors', async ({ page }) => { await page.goto('/birthdays'); await page.getByLabel('Name').fill('Demeter'); await page .getByLabel('Date of birth') .fill('invalid'); await page.getByRole('button').click(); await expect( page.getByText('Demeter...