Skip to content

Commit 7cbbfdf

Browse files
authored
Merge pull request #285 from seamapi/test-with-query
Test DeviceTable loads data
2 parents 0a62093 + 717bfad commit 7cbbfdf

File tree

3 files changed

+38
-16
lines changed

3 files changed

+38
-16
lines changed

src/lib/seam/components/DeviceTable/DeviceTable.test.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@ import { DeviceTable } from './DeviceTable.js'
44

55
test('DeviceTable', async () => {
66
render(<DeviceTable />)
7-
await screen.findByText('...')
7+
await screen.findByText('Front Door')
88
})

src/lib/seam/use-seam-client.ts

+2
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ export function useSeamClient(): {
3939
if (clientSessionToken != null) {
4040
return new Seam({
4141
...clientOptions,
42+
apiKey: undefined,
4243
clientSessionToken,
4344
})
4445
}
@@ -61,6 +62,7 @@ export function useSeamClient(): {
6162

6263
return new Seam({
6364
...clientOptions,
65+
apiKey: undefined,
6466
clientSessionToken: res.client_session.token,
6567
})
6668
},

test/fixtures/react.tsx

+35-15
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { SeamProvider } from '@seamapi/react'
2+
import { QueryClient } from '@tanstack/react-query'
23
import { render } from '@testing-library/react'
34
import type { PropsWithChildren } from 'react'
45

@@ -13,26 +14,45 @@ declare global {
1314
var JEST_SEAM_CLIENT_SESSION_TOKEN_2: string
1415
}
1516

16-
function Providers({ children }: PropsWithChildren): JSX.Element {
17-
return (
18-
<SeamProvider
19-
endpoint={globalThis.JEST_SEAM_ENDPOINT}
20-
publishableKey={globalThis.JEST_SEAM_PUBLISHABLE_KEY_1}
21-
userIdentifierKey='some_user'
22-
disableCssInjection
23-
disableFontInjection
24-
>
25-
{children}
26-
</SeamProvider>
27-
)
28-
}
29-
3017
type Render = typeof render
3118

3219
const customRender = (
3320
ui: Parameters<Render>[0],
3421
options?: Parameters<Render>[1]
35-
): ReturnType<Render> => render(ui, { wrapper: Providers, ...options })
22+
): ReturnType<Render> => {
23+
const queryClient = createQueryClient()
24+
const Providers = createProviders({ queryClient })
25+
return render(ui, { wrapper: Providers, ...options })
26+
}
27+
28+
const createQueryClient = (): QueryClient =>
29+
new QueryClient({
30+
defaultOptions: {
31+
queries: {
32+
retry: false,
33+
// UPSTREAM: Prevent "Jest did not exit one second after the test run completed" error message.
34+
// https://tanstack.com/query/v4/docs/react/guides/testing#set-cachetime-to-infinity-with-jest
35+
cacheTime: Infinity,
36+
},
37+
},
38+
})
39+
40+
const createProviders = ({ queryClient }: { queryClient: QueryClient }) => {
41+
return function Providers({ children }: PropsWithChildren): JSX.Element {
42+
return (
43+
<SeamProvider
44+
queryClient={queryClient}
45+
endpoint={globalThis.JEST_SEAM_ENDPOINT}
46+
publishableKey={globalThis.JEST_SEAM_PUBLISHABLE_KEY_1}
47+
userIdentifierKey='some_user'
48+
disableCssInjection
49+
disableFontInjection
50+
>
51+
{children}
52+
</SeamProvider>
53+
)
54+
}
55+
}
3656

3757
// eslint-disable-next-line import/export
3858
export * from '@testing-library/react'

0 commit comments

Comments
 (0)