MCPcopy Index your code
hub / github.com/TanStack/db / expectIndexUsage

Function expectIndexUsage

packages/db/tests/query/indexes.test.ts:135–167  ·  view source on GitHub ↗
(
  stats: IndexUsageStats,
  expectations: {
    shouldUseIndex: boolean
    shouldUseFullScan?: boolean
    indexCallCount?: number
    fullScanCallCount?: number
  },
)

Source from the content-addressed store, hash-verified

133
134// Helper to assert index usage
135function expectIndexUsage(
136 stats: IndexUsageStats,
137 expectations: {
138 shouldUseIndex: boolean
139 shouldUseFullScan?: boolean
140 indexCallCount?: number
141 fullScanCallCount?: number
142 },
143) {
144 if (expectations.shouldUseIndex) {
145 expect(stats.rangeQueryCalls).toBeGreaterThan(0)
146 expect(stats.indexesUsed.length).toBeGreaterThan(0)
147
148 if (expectations.indexCallCount !== undefined) {
149 expect(stats.rangeQueryCalls).toBe(expectations.indexCallCount)
150 }
151 } else {
152 expect(stats.rangeQueryCalls).toBe(0)
153 expect(stats.indexesUsed.length).toBe(0)
154 }
155
156 if (expectations.shouldUseFullScan !== undefined) {
157 if (expectations.shouldUseFullScan) {
158 expect(stats.fullScanCalls).toBeGreaterThan(0)
159
160 if (expectations.fullScanCallCount !== undefined) {
161 expect(stats.fullScanCalls).toBe(expectations.fullScanCallCount)
162 }
163 } else {
164 expect(stats.fullScanCalls).toBe(0)
165 }
166 }
167}
168
169// Helper to run a test with index usage tracking (automatically handles setup/cleanup)
170function withIndexTracking(

Callers 1

indexes.test.tsFile · 0.70

Calls 1

expectFunction · 0.90

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…