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

DbProvider.test.tsx

24 lines762 Bytes

1import { describe, expect, it } from 'vitest'
2import { renderHook } from '@testing-library/react'
3import { DbClient } from '@tanstack/db'
4import { DbProvider, useDbClient } from '../src/DbProvider'
5import type { ReactNode } from 'react'
6​
7describe(`DbProvider`, () => {
8 it(`provides a DbClient to hooks`, () => {
9 const client = new DbClient()
10 const wrapper = ({ children }: { children: ReactNode }) => (
11 <DbProvider client={client}>{children}</DbProvider>
12 )
13​
14 const { result } = renderHook(() => useDbClient(), { wrapper })
15​
16 expect(result.current).toBe(client)
17 })
18​
19 it(`throws without a provider`, () => {
20 expect(() => renderHook(() => useDbClient())).toThrow(
21 /useDbClient must be used within a DbProvider/,
22 )
23 })
24})