Open History to see the last commit
1import { afterEach, beforeEach, describe, expect, it } from 'vitest'
2import { userEvent } from '@testing-library/user-event'
3import { mount, unmount } from 'svelte'
4import TestForm, { getSampleData } from './large.svelte'
5β
6describe('Svelte Tests', () => {
7 let element: HTMLDivElement
8 let instance: any
9 beforeEach(async () => {
10 element = document.createElement('div')
11 document.body.appendChild(element)
12 instance = mount(TestForm, {
13 target: element,
14 })
15 })
16β
17 afterEach(() => {
18 unmount(instance)
19 element.remove()
20 })
21β
22 it('should have initial values', async () => {
23 expect(element.querySelector<HTMLInputElement>('#firstName')).toHaveValue(
24 getSampleData().firstName,
25 )
26 })
27β
28 it('should mirror user input', async () => {
29 const firstName = element.querySelector<HTMLInputElement>('#firstName')!
30 const firstNameValue = 'Jobs'
31 await userEvent.type(firstName, firstNameValue)
32β
33 const form = JSON.parse(element.querySelector('pre')!.textContent!)
34 expect(form.values.firstName).toBe(
35 getSampleData().firstName + firstNameValue,
36 )
37 })
38})