Writing a failing test
In this section, you’ll write your first unit test for the Vitest test runner.
Create a new file named src/routes/birthdays/Birthday.test.js
and start with the following import
statements:
import { describe, it, expect } from 'vitest'; import { render, screen } from '@testing-library/svelte'; import Birthday from './Birthday.svelte';
The describe
function is used to group tests into a suite of tests. Every test file (such as Birthday.test.js
) will have at least one describe
block. These blocks can also be nested; in future chapters, we’ll look at a couple of scenarios where you’ll want to do this. For example, in Chapter 4, Saving Form Data, you’ll use them to group tests according to the individual form fields that appear within an HTML form.
The it
function is a basic function for defining unit tests, and it is named this way so that the test description reads like...