-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
test(query-core): add test case for infiniteQueryBehavior #9101
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
base: main
Are you sure you want to change the base?
test(query-core): add test case for infiniteQueryBehavior #9101
Conversation
View your CI Pipeline Execution ↗ for commit f0e7fad.
☁️ Nx Cloud last updated this comment at |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #9101 +/- ##
===========================================
+ Coverage 44.50% 58.84% +14.34%
===========================================
Files 204 139 -65
Lines 8148 5402 -2746
Branches 1817 1438 -379
===========================================
- Hits 3626 3179 -447
+ Misses 4079 1923 -2156
+ Partials 443 300 -143 🚀 New features to boost your workflow:
|
const key = queryKey() | ||
|
||
const queryFnSpy = vi.fn().mockImplementation(({ pageParam }) => { | ||
return pageParam | ||
}) | ||
|
||
const observer = new InfiniteQueryObserver<number>(queryClient, { | ||
queryKey: key, | ||
queryFn: queryFnSpy, | ||
getNextPageParam: (lastPage) => (lastPage === 1 ? null : lastPage + 1), | ||
initialPageParam: 1, | ||
}) | ||
|
||
let observerResult: | ||
| InfiniteQueryObserverResult<unknown, unknown> | ||
| undefined | ||
|
||
const unsubscribe = observer.subscribe((result) => { | ||
observerResult = result | ||
}) |
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.
In my opinion, this test don't need mocked function
const key = queryKey() | |
const queryFnSpy = vi.fn().mockImplementation(({ pageParam }) => { | |
return pageParam | |
}) | |
const observer = new InfiniteQueryObserver<number>(queryClient, { | |
queryKey: key, | |
queryFn: queryFnSpy, | |
getNextPageParam: (lastPage) => (lastPage === 1 ? null : lastPage + 1), | |
initialPageParam: 1, | |
}) | |
let observerResult: | |
| InfiniteQueryObserverResult<unknown, unknown> | |
| undefined | |
const unsubscribe = observer.subscribe((result) => { | |
observerResult = result | |
}) | |
const key = queryKey() | |
const observer = new InfiniteQueryObserver(queryClient, { | |
queryKey: key, | |
queryFn: ({ pageParam }) => sleep(0).then(() => pageParam), | |
getNextPageParam: (lastPage) => (lastPage === 1 ? null : lastPage + 1), | |
initialPageParam: 1, | |
}) | |
let observerResult: | |
| InfiniteQueryObserverResult<InfiniteData<number, unknown>, Error> | |
| undefined | |
const unsubscribe = observer.subscribe((result) => { | |
observerResult = result | |
}) |
@@ -441,4 +441,71 @@ describe('InfiniteQueryBehavior', () => { | |||
|
|||
unsubscribe() | |||
}) | |||
|
|||
test('InfiniteQueryBehavior should handle null page parameters correctly', async () => { |
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.
The test name InfiniteQueryBehavior should handle null page parameters correctly
is a bit vague. Consider specifying what “correctly” means in this context
const queryFnSpy = vi.fn().mockImplementation(({ pageParam }) => { | ||
return pageParam | ||
}) |
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.
This function don't have to be mocked
I improved test coverage of
infiniteQueryBehavior
from 94.54% to 100%Before
After