Skip to content

Commit a137fca

Browse files
kevin-dpclaude
andcommitted
test: fix type errors in inject-live-query test helpers
- Add NonSingleResult to createMockCollection return type since mock collections are never singleResult - Add non-null assertions for collection() signal access in tests Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 0689ccc commit a137fca

1 file changed

Lines changed: 14 additions & 12 deletions

File tree

packages/angular-db/tests/inject-live-query.test.ts

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import type {
1414
CollectionStatus,
1515
Context,
1616
LiveQueryCollectionConfig,
17+
NonSingleResult,
1718
QueryBuilder,
1819
} from '@tanstack/db'
1920

@@ -66,12 +67,13 @@ async function waitForAngularUpdate() {
6667
function createMockCollection<T extends object, K extends string | number>(
6768
initial: Array<T & Record<`id`, K>> = [],
6869
initialStatus: CollectionStatus = `ready`,
69-
): Collection<T, K, Record<string, never>> & {
70-
__setStatus: (s: CollectionStatus) => void
71-
__replaceAll: (rows: Array<T & Record<`id`, K>>) => void
72-
__upsert: (row: T & Record<`id`, K>) => void
73-
__delete: (key: K) => void
74-
} {
70+
): Collection<T, K, Record<string, never>> &
71+
NonSingleResult & {
72+
__setStatus: (s: CollectionStatus) => void
73+
__replaceAll: (rows: Array<T & Record<`id`, K>>) => void
74+
__upsert: (row: T & Record<`id`, K>) => void
75+
__delete: (key: K) => void
76+
} {
7577
const map = new Map<K, T>()
7678
for (const r of initial) {
7779
map.set(r.id, r)
@@ -532,7 +534,7 @@ describe(`injectLiveQuery`, () => {
532534

533535
await waitForAngularUpdate()
534536

535-
expect(res.collection().id).toEqual(expect.any(String))
537+
expect(res.collection()!.id).toEqual(expect.any(String))
536538
expect(res.status()).toBe(`ready`)
537539
expect(Array.isArray(res.data())).toBe(true)
538540
expect(res.state() instanceof Map).toBe(true)
@@ -565,7 +567,7 @@ describe(`injectLiveQuery`, () => {
565567
const res = injectLiveQuery(config)
566568
await waitForAngularUpdate()
567569

568-
expect(res.collection().id).toEqual(expect.any(String))
570+
expect(res.collection()!.id).toEqual(expect.any(String))
569571
expect(res.isReady()).toBe(true)
570572
})
571573
})
@@ -611,7 +613,7 @@ describe(`injectLiveQuery`, () => {
611613

612614
await waitForAngularUpdate()
613615

614-
expect(res.collection().id).toEqual(expect.any(String))
616+
expect(res.collection()!.id).toEqual(expect.any(String))
615617
expect(res.status()).toBe(`ready`)
616618
expect(Array.isArray(res.data())).toBe(true)
617619
expect(res.state() instanceof Map).toBe(true)
@@ -829,7 +831,7 @@ describe(`injectLiveQuery`, () => {
829831
})
830832

831833
// Start the live query sync manually
832-
liveQueryCollection().preload()
834+
liveQueryCollection()!.preload()
833835

834836
await waitForAngularUpdate()
835837

@@ -941,7 +943,7 @@ describe(`injectLiveQuery`, () => {
941943
})
942944

943945
// Start the live query sync manually
944-
liveQueryCollection().preload()
946+
liveQueryCollection()!.preload()
945947

946948
await waitForAngularUpdate()
947949

@@ -1041,7 +1043,7 @@ describe(`injectLiveQuery`, () => {
10411043
})
10421044

10431045
// Start the live query sync manually
1044-
liveQueryCollection().preload()
1046+
liveQueryCollection()!.preload()
10451047

10461048
await waitForAngularUpdate()
10471049

0 commit comments

Comments
 (0)