Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@ describe('injectQuery', () => {

expect(spy).toHaveBeenCalledTimes(2)
// should call queryFn with context containing the new queryKey
expect(spy).toHaveBeenCalledWith({
expect(spy).toHaveBeenNthCalledWith(2, {
client: queryClient,
meta: undefined,
queryKey: key2,
Expand Down Expand Up @@ -528,7 +528,8 @@ describe('injectQuery', () => {

void query.refetch().then(() => {
expect(fetchFn).toHaveBeenCalledTimes(1)
expect(fetchFn).toHaveBeenCalledWith(
expect(fetchFn).toHaveBeenNthCalledWith(
1,
expect.objectContaining({
queryKey: [...key, 'key11'],
}),
Expand All @@ -541,7 +542,8 @@ describe('injectQuery', () => {

void query.refetch().then(() => {
expect(fetchFn).toHaveBeenCalledTimes(2)
expect(fetchFn).toHaveBeenCalledWith(
expect(fetchFn).toHaveBeenNthCalledWith(
2,
expect.objectContaining({
queryKey: [...key, 'key12'],
}),
Expand Down
4 changes: 1 addition & 3 deletions packages/query-core/src/__tests__/mutationCache.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -503,9 +503,7 @@ describe('mutationCache', () => {

expect(testCache.getAll()).toHaveLength(0)
expect(callback).toHaveBeenCalledTimes(1)
expect(callback).toHaveBeenCalledWith(
expect.objectContaining({ type: 'removed', mutation }),
)
expect(callback).toHaveBeenCalledWith({ type: 'removed', mutation })

unsubscribe()
})
Expand Down
7 changes: 2 additions & 5 deletions packages/query-core/src/__tests__/query.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -966,13 +966,10 @@ describe('query', () => {
const unsubscribe = queryClient.getQueryCache().subscribe(fn)

queryClient.setQueryData(key, 'data')
const query = queryClient.getQueryCache().find({ queryKey: key })

await vi.advanceTimersByTimeAsync(10)
expect(fn).toHaveBeenCalledWith(
expect.objectContaining({
type: 'removed',
}),
)
expect(fn).toHaveBeenLastCalledWith({ type: 'removed', query })

expect(queryClient.getQueryCache().findAll()).toHaveLength(0)

Expand Down
10 changes: 6 additions & 4 deletions packages/query-core/src/__tests__/queryCache.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ describe('queryCache', () => {
const unsubscribe = queryCache.subscribe(subscriber)
queryClient.setQueryData(key, 'foo')
const query = queryCache.find({ queryKey: key })
expect(subscriber).toHaveBeenCalledWith({ query, type: 'added' })
expect(subscriber).toHaveBeenNthCalledWith(1, { query, type: 'added' })
unsubscribe()
})

Expand All @@ -37,7 +37,8 @@ describe('queryCache', () => {
queryFn: () => sleep(100).then(() => 'data'),
})
await vi.advanceTimersByTimeAsync(100)
expect(callback).toHaveBeenCalled()
const query = queryCache.find({ queryKey: key })
expect(callback).toHaveBeenNthCalledWith(1, { query, type: 'added' })
})

it('should notify query cache when a query becomes stale', async () => {
Expand Down Expand Up @@ -89,7 +90,7 @@ describe('queryCache', () => {
})
await vi.advanceTimersByTimeAsync(100)
const query = queryCache.find({ queryKey: key })
expect(callback).toHaveBeenCalledWith({ query, type: 'added' })
expect(callback).toHaveBeenNthCalledWith(1, { query, type: 'added' })
})

it('should notify subscribers when new query with initialData is added', async () => {
Expand All @@ -102,7 +103,8 @@ describe('queryCache', () => {
initialData: 'initial',
})
await vi.advanceTimersByTimeAsync(100)
expect(callback).toHaveBeenCalled()
const query = queryCache.find({ queryKey: key })
expect(callback).toHaveBeenNthCalledWith(1, { query, type: 'added' })
})

it('should be able to limit cache size', async () => {
Expand Down
10 changes: 9 additions & 1 deletion packages/query-core/src/__tests__/queryClient.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1614,7 +1614,15 @@ describe('queryClient', () => {

queryClient.resetQueries({ queryKey: key })

expect(callback).toHaveBeenCalled()
const query = queryCache.find({ queryKey: key })
expect(callback).toHaveBeenNthCalledWith(
1,
expect.objectContaining({
type: 'updated',
query,
action: expect.objectContaining({ type: 'setState' }),
}),
)
})

it('should reset query', async () => {
Expand Down
9 changes: 6 additions & 3 deletions packages/query-core/src/__tests__/queryObserver.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1240,10 +1240,13 @@ describe('queryObserver', () => {
const unsubscribe = queryClient.getQueryCache().subscribe(spy)
observer.setOptions({ queryKey: key, enabled: false, refetchInterval: 10 })

const query = queryClient.getQueryCache().find({ queryKey: key })
expect(spy).toHaveBeenCalledTimes(1)
expect(spy).toHaveBeenCalledWith(
expect.objectContaining({ type: 'observerOptionsUpdated' }),
)
expect(spy).toHaveBeenCalledWith({
type: 'observerOptionsUpdated',
query,
observer,
})

unsubscribe()
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ describe('PiPContext', () => {
})

expect(consoleError).toHaveBeenCalledWith(
expect.stringContaining('Failed to open popup'),
'Failed to open popup. Please allow popups for this site to view the devtools in picture-in-picture mode.',
)
expect(localStorage.getItem('TanstackQueryDevtools.pip_open')).toBe(
'false',
Expand Down Expand Up @@ -428,10 +428,11 @@ describe('PiPContext', () => {
disabled: true,
})

expect(observeSpy).toHaveBeenCalledWith(
gooberStyle,
expect.objectContaining({ childList: true, subtree: true }),
)
expect(observeSpy).toHaveBeenCalledWith(gooberStyle, {
childList: true,
subtree: true,
characterDataOldValue: true,
})
} finally {
gooberStyle.remove()
}
Expand Down
6 changes: 4 additions & 2 deletions packages/vue-query/src/__tests__/useQuery.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,8 @@ describe('useQuery', () => {
expect(fetchFn).not.toHaveBeenCalled()
await query.refetch()
expect(fetchFn).toHaveBeenCalledTimes(1)
expect(fetchFn).toHaveBeenCalledWith(
expect(fetchFn).toHaveBeenNthCalledWith(
1,
expect.objectContaining({
queryKey: [...key, 'key11'],
}),
Expand All @@ -341,7 +342,8 @@ describe('useQuery', () => {
keyRef.value = 'key12'
await query.refetch()
expect(fetchFn).toHaveBeenCalledTimes(2)
expect(fetchFn).toHaveBeenCalledWith(
expect(fetchFn).toHaveBeenNthCalledWith(
2,
expect.objectContaining({
queryKey: [...key, 'key12'],
}),
Expand Down
Loading