Skip to content

Commit df1de28

Browse files
committed
Fix dedupe unit test
1 parent 239888d commit df1de28

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

packages/query-db-collection/tests/query.test.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3424,7 +3424,7 @@ describe(`QueryCollection`, () => {
34243424
expect(collection.has(`4`)).toBe(false)
34253425
})
34263426

3427-
it(`should deduplicate queries and handle GC correctly when queries are ordered and have a LIMIT`, async () => {
3427+
it(`should handle GC correctly when queries are ordered and have a LIMIT`, async () => {
34283428
const baseQueryKey = [`deduplication-gc-test`]
34293429

34303430
// Mock queryFn to return different data based on predicates
@@ -3434,12 +3434,14 @@ describe(`QueryCollection`, () => {
34343434
const { where, limit } = loadSubsetOptions
34353435

34363436
// Query 1: all items with category A (no limit)
3437-
if (isCategory(`A`, where) && !limit) {
3438-
return Promise.resolve([
3437+
if (isCategory(`A`, where)) {
3438+
const items = [
34393439
{ id: `1`, name: `Item 1`, category: `A` },
34403440
{ id: `2`, name: `Item 2`, category: `A` },
34413441
{ id: `3`, name: `Item 3`, category: `A` },
3442-
])
3442+
]
3443+
// Slice to limit if provided
3444+
return Promise.resolve(limit ? items.slice(0, limit) : items)
34433445
}
34443446

34453447
return Promise.resolve([])
@@ -3510,10 +3512,9 @@ describe(`QueryCollection`, () => {
35103512

35113513
await flushPromises()
35123514

3513-
// Second query should still only have been called once
3514-
// since query2 is deduplicated so it is executed against the local collection
3515-
// and not via queryFn
3516-
expect(queryFn).toHaveBeenCalledTimes(1)
3515+
// queryFn should have been called twice
3516+
// because we do not dedupe the 2nd query
3517+
expect(queryFn).toHaveBeenCalledTimes(2)
35173518

35183519
// Collection should still have all 3 items (deduplication doesn't remove data)
35193520
expect(collection.size).toBe(3)

0 commit comments

Comments
 (0)