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

Function testJoinType

packages/db/tests/query/join.test.ts:106–801  ·  view source on GitHub ↗
(joinType: JoinType, autoIndex: `off` | `eager`)

Source from the content-addressed store, hash-verified

104} as const
105
106function testJoinType(joinType: JoinType, autoIndex: `off` | `eager`) {
107 describe(`${joinType} joins with autoIndex ${autoIndex}`, () => {
108 let usersCollection: ReturnType<typeof createUsersCollection>
109 let departmentsCollection: ReturnType<typeof createDepartmentsCollection>
110
111 beforeEach(() => {
112 usersCollection = createUsersCollection(autoIndex)
113 departmentsCollection = createDepartmentsCollection(autoIndex)
114 })
115
116 test(`should perform ${joinType} join with explicit select`, () => {
117 const joinQuery = createLiveQueryCollection({
118 startSync: true,
119 query: (q) =>
120 q
121 .from({ user: usersCollection })
122 .join(
123 { dept: departmentsCollection },
124 ({ user, dept }) => eq(user.department_id, dept.id),
125 joinType,
126 )
127 .select(({ user, dept }) => ({
128 user_name: user.name,
129 department_name: dept.name,
130 budget: dept.budget,
131 })),
132 })
133
134 const results = joinQuery.toArray
135 const expected = expectedResults[joinType]
136
137 expect(results).toHaveLength(expected.initialCount)
138
139 // Check specific behaviors for each join type
140 if (joinType === `inner`) {
141 // Inner join should only include matching records
142 const userNames = results.map((r) => r.user_name).sort()
143 expect(userNames).toEqual([`Alice`, `Bob`, `Charlie`])
144
145 const alice = results.find((r) => r.user_name === `Alice`)
146 expect(alice).toMatchObject({
147 user_name: `Alice`,
148 department_name: `Engineering`,
149 budget: 100000,
150 })
151 }
152
153 if (joinType === `left`) {
154 // Left join should include all users, even Dave with null department
155 const userNames = results.map((r) => r.user_name).sort()
156 expect(userNames).toEqual([`Alice`, `Bob`, `Charlie`, `Dave`])
157
158 const dave = results.find((r) => r.user_name === `Dave`)
159 expect(dave).toMatchObject({
160 user_name: `Dave`,
161 department_name: undefined,
162 budget: undefined,
163 })

Callers 1

createJoinTestsFunction · 0.85

Calls 15

beforeEachFunction · 0.90
expectFunction · 0.90
createCollectionFunction · 0.85
selectMethod · 0.80
fromMethod · 0.80
filterMethod · 0.80
whereMethod · 0.80
leftJoinMethod · 0.80
rightJoinMethod · 0.80
fullJoinMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…