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

Function createWhereTests

packages/db/tests/query/where.test.ts:235–1795  ·  view source on GitHub ↗
(autoIndex: `off` | `eager`)

Source from the content-addressed store, hash-verified

233}
234
235function createWhereTests(autoIndex: `off` | `eager`): void {
236 describe(`with autoIndex ${autoIndex}`, () => {
237 describe(`Comparison Operators`, () => {
238 let employeesCollection: ReturnType<typeof createEmployeesCollection>
239
240 beforeEach(() => {
241 employeesCollection = createEmployeesCollection(autoIndex)
242 })
243
244 test(`eq operator - equality comparison`, () => {
245 const hireDateEmployee = createLiveQueryCollection({
246 startSync: true,
247 query: (q) =>
248 q
249 .from({ emp: employeesCollection })
250 .where(({ emp }) => eq(emp.hire_date, new Date(`2020-01-15`)))
251 .select(({ emp }) => ({
252 id: emp.id,
253 name: emp.name,
254 active: emp.active,
255 hire_date: emp.hire_date,
256 })),
257 })
258 for (const emp of hireDateEmployee.toArray) {
259 expect(emp.hire_date).toStrictEqual(new Date(`2020-01-15`))
260 }
261 expect(hireDateEmployee.size).toBe(2)
262
263 const activeEmployees = createLiveQueryCollection({
264 startSync: true,
265 query: (q) =>
266 q
267 .from({ emp: employeesCollection })
268 .where(({ emp }) => eq(emp.active, true))
269 .select(({ emp }) => ({
270 id: emp.id,
271 name: emp.name,
272 active: emp.active,
273 })),
274 })
275
276 expect(activeEmployees.size).toBe(4) // Alice, Bob, Diana, Eve
277 expect(activeEmployees.toArray.every((emp) => emp.active)).toBe(true)
278
279 // Test with number equality
280 const specificEmployee = createLiveQueryCollection({
281 startSync: true,
282 query: (q) =>
283 q
284 .from({ emp: employeesCollection })
285 .where(({ emp }) => eq(emp.id, 1))
286 .select(({ emp }) => ({ id: emp.id, name: emp.name })),
287 })
288
289 expect(specificEmployee.size).toBe(1)
290 expect(specificEmployee.get(1)?.name).toBe(`Alice Johnson`)
291
292 // Test live updates

Callers 1

where.test.tsFile · 0.85

Calls 15

beforeEachFunction · 0.90
expectFunction · 0.90
likeFunction · 0.85
inArrayFunction · 0.85
isNullFunction · 0.85
upperFunction · 0.85
lowerFunction · 0.85
lengthFunction · 0.85
coalesceFunction · 0.85
addFunction · 0.85
createCollectionFunction · 0.85

Tested by

no test coverage detected