Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test for useLiveQuery using WHERE ANY #548

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions packages/pglite-vue/test/hooks.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,32 @@ describe('hooks', () => {
},
])
})

it('updates when query contains WHERE ANY', async () => {
const { useLiveQuery } = await import('../src')
await db.exec(`INSERT INTO test (name) VALUES ('test1'),('test2');`)

const ids = await db.query(`SELECT id FROM test`)
expect(ids.rows.length).toBe(2)

const result = useLiveQuery(`SELECT * FROM test WHERE id = ANY($1)`, [
[1, 2],
])
await flushPromises()

await db.exec(`UPDATE test SET name = 'foobar' WHERE name = 'test2';`)
await flushPromises()
expect(result?.rows?.value).toEqual([
{
id: 1,
name: 'test1',
},
{
id: 2,
name: 'foobar',
},
])
})
})
})
function testLiveQuery(queryHook: 'useLiveQuery' | 'useLiveIncrementalQuery') {
Expand Down