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

Function createBasicTests

packages/db/tests/query/basic.test.ts:109–1075  ·  view source on GitHub ↗
(autoIndex: `off` | `eager`)

Source from the content-addressed store, hash-verified

107}
108
109function createBasicTests(autoIndex: `off` | `eager`) {
110 describe(`with autoIndex ${autoIndex}`, () => {
111 let usersCollection: ReturnType<typeof createUsersCollection>
112
113 beforeEach(() => {
114 usersCollection = createUsersCollection(autoIndex)
115 })
116
117 test(`should create, update and delete a live query collection with config`, () => {
118 const liveCollection = createLiveQueryCollection({
119 startSync: true,
120 query: (q) =>
121 q.from({ user: usersCollection }).select(({ user }) => ({
122 id: user.id,
123 name: user.name,
124 age: user.age,
125 email: user.email,
126 active: user.active,
127 })),
128 })
129
130 const results = liveCollection.toArray
131
132 expect(results).toHaveLength(4)
133 expect(results.map((u) => u.name)).toEqual(
134 expect.arrayContaining([`Alice`, `Bob`, `Charlie`, `Dave`]),
135 )
136
137 // Insert a new user
138 const newUser = {
139 id: 5,
140 name: `Eve`,
141 age: 28,
142 email: `eve@example.com`,
143 active: true,
144 }
145 usersCollection.utils.begin()
146 usersCollection.utils.write({
147 type: `insert`,
148 value: newUser,
149 })
150 usersCollection.utils.commit()
151
152 expect(liveCollection.size).toBe(5)
153 expect(liveCollection.get(5)).toMatchObject(newUser)
154
155 // Update the new user
156 const updatedUser = { ...newUser, name: `Eve Updated` }
157 usersCollection.utils.begin()
158 usersCollection.utils.write({
159 type: `update`,
160 value: updatedUser,
161 })
162 usersCollection.utils.commit()
163
164 expect(liveCollection.size).toBe(5)
165 expect(liveCollection.get(5)).toMatchObject(updatedUser)
166

Callers 1

basic.test.tsFile · 0.85

Calls 15

beforeEachFunction · 0.90
expectFunction · 0.90
upperFunction · 0.85
selectMethod · 0.80
fromMethod · 0.80
whereMethod · 0.80
createUsersCollectionFunction · 0.70
eqFunction · 0.70
gtFunction · 0.70
stripVirtualPropsFunction · 0.50
concatFunction · 0.50

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…