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

test-setup.ts

39 lines1.3 KB

1import '@testing-library/jest-dom/vitest'
2import { cleanup } from '@solidjs/testing-library'
3import { resetErrorHalt } from '@solidjs/signals'
4import { afterEach, vi } from 'vitest'
5​
6/**
7 * @tanstack/query-devtools is written for Solid 1, where Suspense around
8 * lazy() was optional. During tests, @tanstack/custom-condition causes
9 * query-devtools source to be recompiled against Solid 2's runtime, which
10 * requires lazy() components to be inside a Loading boundary.
11 *
12 * This mock wraps lazy() so the returned component automatically renders
13 * inside a Loading boundary, bridging the Solid 1 β†’ 2 behavioral gap.
14 */
15vi.mock('solid-js', async (importOriginal) => {
16 const mod = await importOriginal<typeof import('solid-js')>()
17 return {
18 ...mod,
19 Suspense: mod.Loading,
20 lazy: (fn: () => Promise<{ default: any }>) => {
21 const Comp = mod.lazy(fn)
22 return (props: any) =>
23 mod.createComponent(mod.Loading, {
24 get children() {
25 return mod.createComponent(Comp, props)
26 },
27 })
28 },
29 }
30})
31​
32// https://github.com/solidjs/solid-testing-library
33afterEach(() => {
34 cleanup()
35 // Tests that intentionally render throwing components (e.g. missing
36 // QueryClient) permanently halt Solid's scheduler. Revive it so
37 // subsequent tests in the same file still run effects.
38 resetErrorHalt()
39})