-
-
Notifications
You must be signed in to change notification settings - Fork 3.5k
test(svelte-query/createQueries): simplify 'queryFn' and add test for success when queries reslove at different times #9494
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
Conversation
View your CI Pipeline Execution ↗ for commit 0e22231
☁️ Nx Cloud last updated this comment at |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #9494 +/- ##
===========================================
+ Coverage 45.30% 89.20% +43.89%
===========================================
Files 208 18 -190
Lines 8283 176 -8107
Branches 1862 31 -1831
===========================================
- Hits 3753 157 -3596
+ Misses 4085 18 -4067
+ Partials 445 1 -444
🚀 New features to boost your workflow:
|
await vi.advanceTimersByTimeAsync(0) | ||
expect(rendered.getByText('Status 1: pending')).toBeInTheDocument() | ||
expect(rendered.getByText('Status 2: pending')).toBeInTheDocument() | ||
|
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.
If queryFn's sleeping time is different, it would be better to add test code for the case after just 10ms, not only this.
await sleep(5) | ||
return 'Success 1' | ||
}, | ||
queryFn: () => sleep(10).then(() => 'Success 1'), | ||
}, | ||
{ | ||
queryKey: ['key-2'], | ||
queryFn: async () => { | ||
await sleep(5) | ||
return 'Success 2' | ||
}, | ||
queryFn: () => sleep(20).then(() => 'Success 2'), |
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.
If queryFn's sleeping time is different 10ms, 20ms, it would be better to add test code for the case after just 10ms, not only for case after 20ms.
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.
If queryFn's sleeping time is different 10ms, 20ms, it would be better to add test code for the case after just 10ms, not only for case after 20ms.
That makes sense. I’ll add the test as you suggested.
…time in 'advanceTimersByTimeAsync'
eed9a97
to
f2d7746
Compare
…time-advanceTimersByTimeAsync-simplify-queryFn
…eslove at different times
test('Render and wait for success when queries resolve at different times', async () => { | ||
const rendered = render(BaseExample, { | ||
props: { | ||
options: { | ||
queries: [ | ||
{ | ||
queryKey: ['key-1'], | ||
queryFn: () => sleep(10).then(() => 'Success 1'), | ||
}, | ||
{ | ||
queryKey: ['key-2'], | ||
queryFn: () => sleep(20).then(() => 'Success 2'), | ||
}, | ||
], | ||
}, | ||
queryClient: new QueryClient(), | ||
}, | ||
}) | ||
|
||
expect(rendered.getByText('Status 1: pending')).toBeInTheDocument() | ||
expect(rendered.getByText('Status 2: pending')).toBeInTheDocument() | ||
|
||
await vi.advanceTimersByTimeAsync(11) | ||
expect(rendered.getByText('Status 1: success')).toBeInTheDocument() | ||
await vi.advanceTimersByTimeAsync(10) | ||
expect(rendered.getByText('Status 2: success')).toBeInTheDocument() | ||
}) | ||
|
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.
If queryFn's sleeping time is different 10ms, 20ms, it would be better to add test code for the case after just 10ms, not only for case after 20ms.
I added the test as you suggested.
…time-advanceTimersByTimeAsync-simplify-queryFn
No description provided.