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
2 changes: 1 addition & 1 deletion eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export default [
'vitest/no-standalone-expect': [
'error',
{
additionalTestBlockFunctions: ['testIf'],
additionalTestBlockFunctions: ['itIf'],
},
],
},
Expand Down
82 changes: 38 additions & 44 deletions packages/vue-query/src/__tests__/vueQueryPlugin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ interface TestApp extends App {
$root: TestApp
}

const testIf = (condition: boolean) => (condition ? it : it.skip)
const itIf = (condition: boolean) => (condition ? it : it.skip)

function getAppMock(withUnmountHook = false): TestApp {
const mock = {
Expand Down Expand Up @@ -61,7 +61,7 @@ describe('VueQueryPlugin', () => {
expect(setupDevtoolsMock).toHaveBeenCalledTimes(0)
})

testIf(isVue2)('should NOT setup devtools by default', () => {
itIf(isVue2)('should NOT setup devtools by default', () => {
const envCopy = process.env.NODE_ENV
process.env.NODE_ENV = 'development'
const setupDevtoolsMock = setupDevtools as Mock
Expand All @@ -75,7 +75,7 @@ describe('VueQueryPlugin', () => {
expect(setupDevtoolsMock).toHaveBeenCalledTimes(0)
})

testIf(isVue2)('should setup devtools', () => {
itIf(isVue2)('should setup devtools', () => {
const envCopy = process.env.NODE_ENV
process.env.NODE_ENV = 'development'
const setupDevtoolsMock = setupDevtools as Mock
Expand All @@ -89,7 +89,7 @@ describe('VueQueryPlugin', () => {
expect(setupDevtoolsMock).toHaveBeenCalledTimes(1)
})

testIf(isVue3)('should NOT setup devtools by default', () => {
itIf(isVue3)('should NOT setup devtools by default', () => {
const envCopy = process.env.NODE_ENV
process.env.NODE_ENV = 'development'
const setupDevtoolsMock = setupDevtools as Mock
Expand All @@ -100,7 +100,7 @@ describe('VueQueryPlugin', () => {
expect(setupDevtoolsMock).toHaveBeenCalledTimes(0)
})

testIf(isVue3)('should setup devtools', () => {
itIf(isVue3)('should setup devtools', () => {
const envCopy = process.env.NODE_ENV
process.env.NODE_ENV = 'development'
const setupDevtoolsMock = setupDevtools as Mock
Expand Down Expand Up @@ -148,7 +148,7 @@ describe('VueQueryPlugin', () => {
})

describe('when called without additional options', () => {
testIf(isVue2)('should provide a client with default clientKey', () => {
itIf(isVue2)('should provide a client with default clientKey', () => {
const appMock = getAppMock()
VueQueryPlugin.install(appMock)

Expand All @@ -159,7 +159,7 @@ describe('VueQueryPlugin', () => {
})
})

testIf(isVue3)('should provide a client with default clientKey', () => {
itIf(isVue3)('should provide a client with default clientKey', () => {
const appMock = getAppMock()
VueQueryPlugin.install(appMock)

Expand All @@ -171,7 +171,7 @@ describe('VueQueryPlugin', () => {
})

describe('when called with custom clientKey', () => {
testIf(isVue2)('should provide a client with customized clientKey', () => {
itIf(isVue2)('should provide a client with customized clientKey', () => {
const appMock = getAppMock()
VueQueryPlugin.install(appMock, { queryClientKey: 'CUSTOM' })

Expand All @@ -182,7 +182,7 @@ describe('VueQueryPlugin', () => {
})
})

testIf(isVue3)('should provide a client with customized clientKey', () => {
itIf(isVue3)('should provide a client with customized clientKey', () => {
const appMock = getAppMock()
VueQueryPlugin.install(appMock, { queryClientKey: 'CUSTOM' })

Expand All @@ -194,7 +194,7 @@ describe('VueQueryPlugin', () => {
})

describe('when called with custom client', () => {
testIf(isVue2)('should provide that custom client', () => {
itIf(isVue2)('should provide that custom client', () => {
const appMock = getAppMock()
const customClient = { mount: vi.fn() } as unknown as QueryClient
VueQueryPlugin.install(appMock, { queryClient: customClient })
Expand All @@ -207,7 +207,7 @@ describe('VueQueryPlugin', () => {
})
})

testIf(isVue3)('should provide that custom client', () => {
itIf(isVue3)('should provide that custom client', () => {
const appMock = getAppMock()
const customClient = { mount: vi.fn() } as unknown as QueryClient
VueQueryPlugin.install(appMock, { queryClient: customClient })
Expand All @@ -221,42 +221,36 @@ describe('VueQueryPlugin', () => {
})

describe('when called with custom client config', () => {
testIf(isVue2)(
'should instantiate a client with the provided config',
() => {
const appMock = getAppMock()
const config = {
defaultOptions: { queries: { enabled: true } },
}
VueQueryPlugin.install(appMock, {
queryClientConfig: config,
})
itIf(isVue2)('should instantiate a client with the provided config', () => {
const appMock = getAppMock()
const config = {
defaultOptions: { queries: { enabled: true } },
}
VueQueryPlugin.install(appMock, {
queryClientConfig: config,
})

appMock._mixin.beforeCreate?.call(appMock)
const client = appMock._provided.VUE_QUERY_CLIENT as QueryClient
const defaultOptions = client.getDefaultOptions()

expect(defaultOptions).toEqual(config.defaultOptions)
},
)

testIf(isVue3)(
'should instantiate a client with the provided config',
() => {
const appMock = getAppMock()
const config = {
defaultOptions: { queries: { enabled: true } },
}
VueQueryPlugin.install(appMock, {
queryClientConfig: config,
})
appMock._mixin.beforeCreate?.call(appMock)
const client = appMock._provided.VUE_QUERY_CLIENT as QueryClient
const defaultOptions = client.getDefaultOptions()

const client = (appMock.provide as Mock).mock.calls[0]?.[1]
const defaultOptions = client.getDefaultOptions()
expect(defaultOptions).toEqual(config.defaultOptions)
})

expect(defaultOptions).toEqual(config.defaultOptions)
},
)
itIf(isVue3)('should instantiate a client with the provided config', () => {
const appMock = getAppMock()
const config = {
defaultOptions: { queries: { enabled: true } },
}
VueQueryPlugin.install(appMock, {
queryClientConfig: config,
})

const client = (appMock.provide as Mock).mock.calls[0]?.[1]
const defaultOptions = client.getDefaultOptions()

expect(defaultOptions).toEqual(config.defaultOptions)
})
})

describe('when persister is provided', () => {
Expand Down
Loading