MCPcopy
hub / github.com/electric-sql/pglite / testLiveQuery

Function testLiveQuery

packages/pglite-react/test/hooks.test.tsx:73–424  ·  view source on GitHub ↗
(queryHook: 'useLiveQuery' | 'useLiveIncrementalQuery')

Source from the content-addressed store, hash-verified

71})
72
73function testLiveQuery(queryHook: 'useLiveQuery' | 'useLiveIncrementalQuery') {
74 describe(queryHook, () => {
75 let db: PGliteWithLive
76 let wrapper: ({
77 children,
78 }: {
79 children: React.ReactNode
80 }) => React.ReactElement
81 const hookFn =
82 queryHook === 'useLiveQuery' ? useLiveQuery : useLiveIncrementalQuery
83 const incKey = 'id'
84 beforeEach(async () => {
85 db = await PGlite.create({
86 extensions: {
87 live,
88 },
89 })
90 wrapper = ({ children }) => {
91 return <PGliteProvider db={db}>{children}</PGliteProvider>
92 }
93
94 await db.exec(`
95 CREATE TABLE IF NOT EXISTS test (
96 id SERIAL PRIMARY KEY,
97 name TEXT
98 );
99 `)
100 await db.exec(`TRUNCATE test;`)
101 })
102
103 it('can receive initial results', async () => {
104 await db.exec(`INSERT INTO test (name) VALUES ('test1'),('test2');`)
105
106 const { result } = renderHook(
107 () => hookFn(`SELECT * FROM test`, [], incKey),
108 { wrapper },
109 )
110
111 await waitFor(() => expect(result.current).not.toBe(undefined))
112 expect(result.current).toEqual({
113 rows: [
114 {
115 id: 1,
116 name: 'test1',
117 },
118 {
119 id: 2,
120 name: 'test2',
121 },
122 ],
123 fields: [
124 {
125 name: 'id',
126 dataTypeID: 23,
127 },
128 {
129 name: 'name',
130 dataTypeID: 25,

Callers 1

hooks.test.tsxFile · 0.70

Calls 6

useLiveQueryFunction · 0.90
describeFunction · 0.85
execMethod · 0.80
incrementalQueryMethod · 0.80
queryMethod · 0.65
createMethod · 0.45

Tested by

no test coverage detected