MCPcopy Create free account
hub / github.com/TanStack/db / expectIndexUsage

Function expectIndexUsage

packages/db/tests/utils.ts:158–190  ·  view source on GitHub ↗
(
  stats: IndexUsageStats,
  expectations: {
    shouldUseIndex: boolean
    shouldUseFullScan?: boolean
    indexCallCount?: number
    fullScanCallCount?: number
  },
)

Source from the content-addressed store, hash-verified

156
157// Helper to assert index usage
158export function expectIndexUsage(
159 stats: IndexUsageStats,
160 expectations: {
161 shouldUseIndex: boolean
162 shouldUseFullScan?: boolean
163 indexCallCount?: number
164 fullScanCallCount?: number
165 },
166) {
167 if (expectations.shouldUseIndex) {
168 expect(stats.rangeQueryCalls).toBeGreaterThan(0)
169 expect(stats.indexesUsed.length).toBeGreaterThan(0)
170
171 if (expectations.indexCallCount !== undefined) {
172 expect(stats.rangeQueryCalls).toBe(expectations.indexCallCount)
173 }
174 } else {
175 expect(stats.rangeQueryCalls).toBe(0)
176 expect(stats.indexesUsed.length).toBe(0)
177 }
178
179 if (expectations.shouldUseFullScan !== undefined) {
180 if (expectations.shouldUseFullScan) {
181 expect(stats.fullScanCalls).toBeGreaterThan(0)
182
183 if (expectations.fullScanCallCount !== undefined) {
184 expect(stats.fullScanCalls).toBe(expectations.fullScanCallCount)
185 }
186 } else {
187 expect(stats.fullScanCalls).toBe(0)
188 }
189 }
190}
191
192// Helper to run a test with index usage tracking (automatically handles setup/cleanup)
193export function withIndexTracking(

Calls 1

expectFunction · 0.90

Tested by

no test coverage detected