Skip to content

Commit f320db5

Browse files
reizamsukvvon
andauthored
test(solid-query): assert exact values instead of loose matchers (#11105)
Co-authored-by: Wonsuk Choi <sukvvon@gmail.com>
1 parent fd50fa1 commit f320db5

4 files changed

Lines changed: 9 additions & 9 deletions

File tree

packages/solid-query/src/__tests__/QueryClientProvider.test.tsx

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ describe('QueryClientProvider', () => {
4141
await vi.advanceTimersByTimeAsync(10)
4242
expect(rendered.getByText('test')).toBeInTheDocument()
4343

44-
expect(queryCache.find({ queryKey: key })).toBeDefined()
44+
expect(queryCache.find({ queryKey: key })?.state.data).toBe('test')
4545
})
4646

4747
it('allows multiple caches to be partitioned', async () => {
@@ -94,10 +94,10 @@ describe('QueryClientProvider', () => {
9494
expect(rendered.getByText('test1')).toBeInTheDocument()
9595
expect(rendered.getByText('test2')).toBeInTheDocument()
9696

97-
expect(queryCache1.find({ queryKey: key1 })).toBeDefined()
98-
expect(queryCache1.find({ queryKey: key2 })).not.toBeDefined()
99-
expect(queryCache2.find({ queryKey: key1 })).not.toBeDefined()
100-
expect(queryCache2.find({ queryKey: key2 })).toBeDefined()
97+
expect(queryCache1.find({ queryKey: key1 })?.state.data).toBe('test1')
98+
expect(queryCache1.find({ queryKey: key2 })).toBeUndefined()
99+
expect(queryCache2.find({ queryKey: key1 })).toBeUndefined()
100+
expect(queryCache2.find({ queryKey: key2 })?.state.data).toBe('test2')
101101
})
102102

103103
it("uses defaultOptions for queries when they don't provide their own config", async () => {
@@ -135,7 +135,6 @@ describe('QueryClientProvider', () => {
135135
await vi.advanceTimersByTimeAsync(10)
136136
expect(rendered.getByText('test')).toBeInTheDocument()
137137

138-
expect(queryCache.find({ queryKey: key })).toBeDefined()
139138
expect(queryCache.find({ queryKey: key })?.options.gcTime).toBe(Infinity)
140139
})
141140

packages/solid-query/src/__tests__/mutationOptions.test.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -507,6 +507,5 @@ describe('mutationOptions', () => {
507507
const lastSnapshot = mutationStateArray[mutationStateArray.length - 1]!
508508
expect(lastSnapshot.length).toEqual(1)
509509
expect(lastSnapshot[0]?.data).toEqual('data1')
510-
expect(lastSnapshot[1]).toBeFalsy()
511510
})
512511
})

packages/solid-query/src/__tests__/suspense.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ describe("useQuery's in Suspense mode", () => {
196196
const rendered = renderWithClient(queryClient, () => <App />)
197197

198198
expect(rendered.queryByText('rendered')).not.toBeInTheDocument()
199-
expect(queryCache.find({ queryKey: key })).toBeFalsy()
199+
expect(queryCache.find({ queryKey: key })).toBeUndefined()
200200

201201
fireEvent.click(rendered.getByLabelText('toggle'))
202202
await vi.advanceTimersByTimeAsync(10)

packages/solid-query/src/__tests__/useQuery.test.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5746,7 +5746,9 @@ describe('useQuery', () => {
57465746
await vi.advanceTimersByTimeAsync(10)
57475747

57485748
expect(rendered.getByText('status: success')).toBeInTheDocument()
5749-
expect(queryClient1.getQueryCache().find({ queryKey: key })).toBeDefined()
5749+
expect(
5750+
queryClient1.getQueryCache().find({ queryKey: key })?.state.data,
5751+
).toBe('data')
57505752
expect(queryFn).toHaveBeenCalledTimes(1)
57515753

57525754
setClient(queryClient2)

0 commit comments

Comments
 (0)