11import { Repo } from '@automerge/automerge-repo' ;
22import { RepoContext } from '@automerge/automerge-repo-react-hooks' ;
33import { Entity , store , Type } from '@graphprotocol/hypergraph' ;
4+ import { QueryClient , QueryClientProvider } from '@tanstack/react-query' ;
45import '@testing-library/jest-dom/vitest' ;
56import { act , cleanup , renderHook , waitFor } from '@testing-library/react' ;
67import type React from 'react' ;
@@ -36,11 +37,18 @@ describe('HypergraphSpaceContext', () => {
3637 const spaceId = '1e5e39da-a00d-4fd8-b53b-98095337112f' ;
3738
3839 let repo = new Repo ( { } ) ;
39- let wrapper = ( { children } : Readonly < { children : React . ReactNode } > ) => (
40- < RepoContext . Provider value = { repo } >
41- < HypergraphSpaceProvider space = { spaceId } > { children } </ HypergraphSpaceProvider >
42- </ RepoContext . Provider >
43- ) ;
40+ const queryClient = new QueryClient ( ) ;
41+ const createWrapper =
42+ ( ) =>
43+ ( { children } : Readonly < { children : React . ReactNode } > ) => (
44+ < RepoContext . Provider value = { repo } >
45+ < QueryClientProvider client = { queryClient } >
46+ < HypergraphSpaceProvider space = { spaceId } > { children } </ HypergraphSpaceProvider >
47+ </ QueryClientProvider >
48+ </ RepoContext . Provider >
49+ ) ;
50+
51+ let wrapper = createWrapper ( ) ;
4452
4553 beforeEach ( ( ) => {
4654 repo = new Repo ( { } ) ;
@@ -63,11 +71,7 @@ describe('HypergraphSpaceContext', () => {
6371 keys : [ ] ,
6472 } ) ;
6573
66- wrapper = ( { children } : Readonly < { children : React . ReactNode } > ) => (
67- < RepoContext . Provider value = { repo } >
68- < HypergraphSpaceProvider space = { spaceId } > { children } </ HypergraphSpaceProvider >
69- </ RepoContext . Provider >
70- ) ;
74+ wrapper = createWrapper ( ) ;
7175 } ) ;
7276
7377 describe ( 'useCreateEntity' , ( ) => {
@@ -92,7 +96,12 @@ describe('HypergraphSpaceContext', () => {
9296 wrapper,
9397 } ,
9498 ) ;
95- expect ( queryEntityResult . current ) . toEqual ( createdEntity ) ;
99+ expect ( queryEntityResult . current ) . toEqual ( {
100+ data : createdEntity ,
101+ invalidEntity : undefined ,
102+ isPending : false ,
103+ isError : false ,
104+ } ) ;
96105 }
97106
98107 rerender ( ) ;
@@ -144,11 +153,16 @@ describe('HypergraphSpaceContext', () => {
144153 wrapper,
145154 } ) ;
146155 expect ( queryEntityResult . current ) . toEqual ( {
147- // @ts -expect-error - TODO: fix the types error
148- ...createdEntity ,
149- __version : '' ,
150- __deleted : false ,
151- __schema : Person ,
156+ data : {
157+ // @ts -expect-error - TODO: fix the types error
158+ ...createdEntity ,
159+ __version : '' ,
160+ __deleted : false ,
161+ __schema : Person ,
162+ } ,
163+ invalidEntity : undefined ,
164+ isPending : false ,
165+ isError : false ,
152166 } ) ;
153167
154168 const { result : queryEntitiesResult , rerender } = renderHook ( ( ) => useQueryLocal ( Person ) , { wrapper } ) ;
0 commit comments