Skip to content

Commit 09a6545

Browse files
committed
test: add invalidateQueries test
1 parent 163339f commit 09a6545

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

src/react/tests/useQuery.test.tsx

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -889,12 +889,20 @@ describe('useQuery', () => {
889889
expect(results[2]).toMatchObject({ data: 'fetched', isFetching: false })
890890
})
891891

892-
it('should update query stale state when invalidated with invalidateQueries', async () => {
892+
it('should update query stale state and refetch when invalidated with invalidateQueries', async () => {
893893
const key = queryKey()
894-
const states: UseQueryResult<string>[] = []
894+
const states: UseQueryResult<number>[] = []
895+
let count = 0
895896

896897
function Page() {
897-
const state = useQuery(key, () => 'data', { staleTime: Infinity })
898+
const state = useQuery(
899+
key,
900+
() => {
901+
count++
902+
return count
903+
},
904+
{ staleTime: Infinity }
905+
)
898906

899907
states.push(state)
900908

@@ -919,19 +927,19 @@ describe('useQuery', () => {
919927
isStale: true,
920928
})
921929
expect(states[1]).toMatchObject({
922-
data: 'data',
930+
data: 1,
923931
isFetching: false,
924932
isSuccess: true,
925933
isStale: false,
926934
})
927935
expect(states[2]).toMatchObject({
928-
data: 'data',
936+
data: 1,
929937
isFetching: true,
930938
isSuccess: true,
931939
isStale: true,
932940
})
933941
expect(states[3]).toMatchObject({
934-
data: 'data',
942+
data: 2,
935943
isFetching: false,
936944
isSuccess: true,
937945
isStale: false,

0 commit comments

Comments
 (0)