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

Await.test.tsx

28 lines737 Bytes

1import { afterEach, describe, expect, it, vi } from 'vitest'
2import { cleanup, render, waitFor } from '@solidjs/testing-library'
3import { Await } from '../src/awaited'
4​
5afterEach(cleanup)
6​
7describe('Await', () => {
8 it.each([
9 ['zero', 0],
10 ['false', false],
11 ['empty string', ''],
12 ['null', null],
13 ['undefined', undefined],
14 ])('renders a resolved %s value', async (_name, value) => {
15 const children = vi.fn(() => <span>resolved</span>)
16​
17 render(() => (
18 <Await promise={Promise.resolve(value)} fallback={<span>pending</span>}>
19 {children}
20 </Await>
21 ))
22​
23 await waitFor(() => {
24 expect(children).toHaveBeenCalledOnce()
25 })
26 expect(children).toHaveBeenCalledWith(value)
27 })
28})