Skip to content
Source
Sign inSign up
TanStack/form
Open History to see the last commit

array.test.ts

25 lines997 Bytes

1import { describe, expect, it } from 'vitest'
2import { render } from '@testing-library/svelte'
3import { userEvent } from '@testing-library/user-event'
4import TestForm from './array.svelte'
5import SwapForm from './array-swap.svelte'
6​
7const user = userEvent.setup()
8​
9describe('Svelte Field array mode', () => {
10 it('should support array mode', async () => {
11 const { getByTestId, getByRole } = render(TestForm)
12 expect(getByTestId('val')).toHaveTextContent('["a"]')
13 await user.click(getByRole('button', { name: 'push' }))
14 expect(getByTestId('val')).toHaveTextContent('["a","b"]')
15 })
16})
17​
18describe('Svelte Field array mode swapFieldValues', () => {
19 it('should rerender on swapFieldValues even when length is unchanged', async () => {
20 const { getByTestId, getByRole } = render(SwapForm)
21 expect(getByTestId('val')).toHaveTextContent('["a","b"]')
22 await user.click(getByRole('button', { name: 'swap' }))
23 expect(getByTestId('val')).toHaveTextContent('["b","a"]')
24 })
25})