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
1 change: 1 addition & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export default [
],
'@typescript-eslint/no-empty-function': 'off',
'@typescript-eslint/no-unsafe-function-type': 'off',
'@typescript-eslint/require-await': 'error',
'no-case-declarations': 'off',
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ describe('injectInfiniteQuery', () => {
vi.useRealTimers()
})

test('should narrow type after isSuccess', async () => {
test('should narrow type after isSuccess', () => {
const query = TestBed.runInInjectionContext(() => {
return injectInfiniteQuery(() => ({
queryKey: ['infiniteQuery'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ describe('broadcastQueryClient', () => {
queryCache = queryClient.getQueryCache()
})

it('should subscribe to the query cache', async () => {
it('should subscribe to the query cache', () => {
broadcastQueryClient({
queryClient,
broadcastChannel: 'test_channel',
})
expect(queryCache.hasListeners()).toBe(true)
})

it('should not have any listeners after cleanup', async () => {
it('should not have any listeners after cleanup', () => {
const unsubscribe = broadcastQueryClient({
queryClient,
broadcastChannel: 'test_channel',
Expand Down
2 changes: 1 addition & 1 deletion packages/query-codemods/eslint.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// @ts-check

import vitest from '@vitest/eslint-plugin'
import rootConfig from './root.eslint.config.js'

export default [
Expand All @@ -9,6 +8,7 @@ export default [
rules: {
'cspell/spellchecker': 'off',
'@typescript-eslint/no-unnecessary-condition': 'off',
'@typescript-eslint/require-await': 'off',
'import/no-duplicates': 'off',
'import/no-unresolved': 'off',
'import/order': 'off',
Expand Down
2 changes: 1 addition & 1 deletion packages/query-core/src/__tests__/queryObserver.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ describe('queryObserver', () => {
vi.useRealTimers()
})

test('should trigger a fetch when subscribed', async () => {
test('should trigger a fetch when subscribed', () => {
const key = queryKey()
const queryFn = vi
.fn<(...args: Array<unknown>) => string>()
Expand Down
2 changes: 1 addition & 1 deletion packages/react-query/src/__tests__/useQuery.test-d.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ describe('useQuery', () => {
)
expectTypeOf(testFuncStyle.data).toEqualTypeOf<boolean | undefined>()

it('should return the correct states for a successful query', async () => {
it('should return the correct states for a successful query', () => {
const state = useQuery<string, Error>({
queryKey: key,
queryFn: () => Promise.resolve('test'),
Expand Down
4 changes: 2 additions & 2 deletions packages/react-query/src/__tests__/useQuery.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -608,7 +608,7 @@ describe('useQuery', () => {
expect(states[1]).toMatchObject({ data: 'test' })
})

it('should not fetch when refetchOnMount is false and data has been fetched already', async () => {
it('should not fetch when refetchOnMount is false and data has been fetched already', () => {
const key = queryKey()
const states: Array<UseQueryResult<string>> = []

Expand Down Expand Up @@ -1106,7 +1106,7 @@ describe('useQuery', () => {
})
})

it('should not refetch disabled query when invalidated with invalidateQueries', async () => {
it('should not refetch disabled query when invalidated with invalidateQueries', () => {
const key = queryKey()
const states: Array<UseQueryResult<number>> = []
let count = 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,72 @@ describe('useSuspenseInfiniteQuery', () => {
)
consoleErrorSpy.mockRestore()
})

it('should log an error when skipToken is used in development environment', () => {
const envCopy = process.env.NODE_ENV
process.env.NODE_ENV = 'development'

const consoleErrorSpy = vi
.spyOn(console, 'error')
.mockImplementation(() => undefined)
const key = queryKey()

function Page() {
useSuspenseInfiniteQuery({
queryKey: key,
queryFn: skipToken as any,
initialPageParam: 1,
getNextPageParam: () => 1,
})

return null
}

renderWithClient(
queryClient,
<React.Suspense fallback="Loading...">
<Page />
</React.Suspense>,
)

expect(consoleErrorSpy).toHaveBeenCalledWith(
'skipToken is not allowed for useSuspenseInfiniteQuery',
)

consoleErrorSpy.mockRestore()
process.env.NODE_ENV = envCopy
})

it('should not log an error when skipToken is used in production environment', () => {
const envCopy = process.env.NODE_ENV
process.env.NODE_ENV = 'production'

const consoleErrorSpy = vi
.spyOn(console, 'error')
.mockImplementation(() => undefined)
const key = queryKey()

function Page() {
useSuspenseInfiniteQuery({
queryKey: key,
queryFn: skipToken as any,
initialPageParam: 1,
getNextPageParam: () => 1,
})

return null
}

renderWithClient(
queryClient,
<React.Suspense fallback="Loading...">
<Page />
</React.Suspense>,
)

expect(consoleErrorSpy).not.toHaveBeenCalled()

consoleErrorSpy.mockRestore()
process.env.NODE_ENV = envCopy
})
})
72 changes: 72 additions & 0 deletions packages/react-query/src/__tests__/useSuspenseQueries.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -713,4 +713,76 @@ describe('useSuspenseQueries 2', () => {
)
consoleErrorSpy.mockRestore()
})

it('should log an error when skipToken is used in development environment', () => {
const envCopy = process.env.NODE_ENV
process.env.NODE_ENV = 'development'

const consoleErrorSpy = vi
.spyOn(console, 'error')
.mockImplementation(() => undefined)
const key = queryKey()

function Page() {
useSuspenseQueries({
queries: [
{
queryKey: key,
queryFn: skipToken as any,
},
],
})

return null
}

renderWithClient(
queryClient,
<React.Suspense fallback="Loading...">
<Page />
</React.Suspense>,
)

expect(consoleErrorSpy).toHaveBeenCalledWith(
'skipToken is not allowed for useSuspenseQueries',
)

consoleErrorSpy.mockRestore()
process.env.NODE_ENV = envCopy
})

it('should not log an error when skipToken is used in production environment', () => {
const envCopy = process.env.NODE_ENV
process.env.NODE_ENV = 'production'

const consoleErrorSpy = vi
.spyOn(console, 'error')
.mockImplementation(() => undefined)
const key = queryKey()

function Page() {
useSuspenseQueries({
queries: [
{
queryKey: key,
queryFn: skipToken as any,
},
],
})

return null
}

renderWithClient(
queryClient,
<React.Suspense fallback="Loading...">
<Page />
</React.Suspense>,
)

expect(consoleErrorSpy).not.toHaveBeenCalled()

consoleErrorSpy.mockRestore()
process.env.NODE_ENV = envCopy
})
})
64 changes: 64 additions & 0 deletions packages/react-query/src/__tests__/useSuspenseQuery.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -967,4 +967,68 @@ describe('useSuspenseQuery', () => {

expect(count).toBeGreaterThanOrEqual(3)
})

it('should log an error when skipToken is used in development environment', () => {
const envCopy = process.env.NODE_ENV
process.env.NODE_ENV = 'development'

const consoleErrorSpy = vi
.spyOn(console, 'error')
.mockImplementation(() => undefined)
const key = queryKey()

function Page() {
useSuspenseQuery({
queryKey: key,
queryFn: skipToken as any,
})

return null
}

renderWithClient(
queryClient,
<React.Suspense fallback="Loading...">
<Page />
</React.Suspense>,
)

expect(consoleErrorSpy).toHaveBeenCalledWith(
'skipToken is not allowed for useSuspenseQuery',
)

consoleErrorSpy.mockRestore()
process.env.NODE_ENV = envCopy
})

it('should not log an error when skipToken is used in production environment', () => {
const envCopy = process.env.NODE_ENV
process.env.NODE_ENV = 'production'

const consoleErrorSpy = vi
.spyOn(console, 'error')
.mockImplementation(() => undefined)
const key = queryKey()

function Page() {
useSuspenseQuery({
queryKey: key,
queryFn: skipToken as any,
})

return null
}

renderWithClient(
queryClient,
<React.Suspense fallback="Loading...">
<Page />
</React.Suspense>,
)

expect(consoleErrorSpy).not.toHaveBeenCalled()

consoleErrorSpy.mockRestore()
process.env.NODE_ENV = envCopy
})
})
Loading