-
-
Notifications
You must be signed in to change notification settings - Fork 3.3k
fix(query-core): add error management around this.setData(data) #7642
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
b6ca8cf
4e307a2
3277657
1a0934f
8b4edd3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -943,4 +943,39 @@ describe('query', () => { | |||||||||||
await sleep(60) // let it resolve | ||||||||||||
expect(spy).toHaveBeenCalledWith('1 - 2') | ||||||||||||
}) | ||||||||||||
|
||||||||||||
it('should call onError when setData throws', async () => { | ||||||||||||
const key = queryKey() | ||||||||||||
|
||||||||||||
const queryFn = vi.fn<Array<unknown>, unknown>() | ||||||||||||
|
||||||||||||
queryFn.mockImplementation(async () => { | ||||||||||||
await sleep(50) | ||||||||||||
const data: Array<{ | ||||||||||||
id: number | ||||||||||||
name: string | ||||||||||||
link: null | { id: number; name: string; link: unknown } | ||||||||||||
}> = Array.from({ length: 5 }) | ||||||||||||
.fill(null) | ||||||||||||
.map((_, index) => ({ | ||||||||||||
id: index, | ||||||||||||
name: `name-${index}`, | ||||||||||||
link: null, | ||||||||||||
})) | ||||||||||||
|
||||||||||||
if (data[0] && data[1]) { | ||||||||||||
data[0].link = data[1] | ||||||||||||
data[1].link = data[0] | ||||||||||||
} | ||||||||||||
|
||||||||||||
return data | ||||||||||||
}) | ||||||||||||
|
||||||||||||
queryClient.prefetchQuery({ queryKey: key, queryFn }) | ||||||||||||
const query = queryCache.find({ queryKey: key })! | ||||||||||||
await sleep(100) | ||||||||||||
Comment on lines
+974
to
+976
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||
expect(queryFn).toHaveBeenCalledTimes(1) | ||||||||||||
await query.fetch() | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't understand why we fetch twice: first with the prefetching, and then with |
||||||||||||
expect(query.state.status).toBe('error') | ||||||||||||
}) | ||||||||||||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's get those numbers down: