Skip to content

Commit bfca951

Browse files
committed
test: avoid hard-coding async-data keys
1 parent 9b45da7 commit bfca951

File tree

1 file changed

+18
-18
lines changed

1 file changed

+18
-18
lines changed

test/nuxt/use-async-data.test.ts

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -348,27 +348,27 @@ describe('useAsyncData', () => {
348348

349349
it('should execute the promise function once when dedupe option is "defer" for multiple calls', () => {
350350
const promiseFn = vi.fn(() => Promise.resolve('test'))
351-
useAsyncData('dedupedKey', promiseFn, { dedupe: 'defer' })
352-
useAsyncData('dedupedKey', promiseFn, { dedupe: 'defer' })
353-
useAsyncData('dedupedKey', promiseFn, { dedupe: 'defer' })
351+
useAsyncData(uniqueKey, promiseFn, { dedupe: 'defer' })
352+
useAsyncData(uniqueKey, promiseFn, { dedupe: 'defer' })
353+
useAsyncData(uniqueKey, promiseFn, { dedupe: 'defer' })
354354

355355
expect(promiseFn).toHaveBeenCalledTimes(1)
356356
})
357357

358358
it('should execute the promise function multiple times when dedupe option is not specified for multiple calls', () => {
359359
const promiseFn = vi.fn(() => Promise.resolve('test'))
360-
useAsyncData('dedupedKey1', promiseFn)
361-
useAsyncData('dedupedKey1', promiseFn)
362-
useAsyncData('dedupedKey1', promiseFn)
360+
useAsyncData(uniqueKey, promiseFn)
361+
useAsyncData(uniqueKey, promiseFn)
362+
useAsyncData(uniqueKey, promiseFn)
363363

364364
expect(promiseFn).toHaveBeenCalledTimes(3)
365365
})
366366

367367
it('should execute the promise function as per dedupe option when different dedupe options are used for multiple calls', () => {
368368
const promiseFn = vi.fn(() => Promise.resolve('test'))
369-
useAsyncData('dedupedKey2', promiseFn, { dedupe: 'defer' })
370-
useAsyncData('dedupedKey2', promiseFn)
371-
useAsyncData('dedupedKey2', promiseFn, { dedupe: 'defer' })
369+
useAsyncData(uniqueKey, promiseFn, { dedupe: 'defer' })
370+
useAsyncData(uniqueKey, promiseFn)
371+
useAsyncData(uniqueKey, promiseFn, { dedupe: 'defer' })
372372

373373
expect(promiseFn).toHaveBeenCalledTimes(2)
374374
})
@@ -388,24 +388,24 @@ describe('useAsyncData', () => {
388388
warn.mockClear()
389389
count++
390390

391-
await mountWithAsyncData(`dedupedKey3-${count}`, () => Promise.resolve('test'), { [opt]: () => ({}) })
392-
await mountWithAsyncData(`dedupedKey3-${count}`, () => Promise.resolve('test'), { [opt]: () => ({}) })
391+
await mountWithAsyncData(`${uniqueKey}-${count}`, () => Promise.resolve('test'), { [opt]: () => ({}) })
392+
await mountWithAsyncData(`${uniqueKey}-${count}`, () => Promise.resolve('test'), { [opt]: () => ({}) })
393393
expect(warn).not.toHaveBeenCalled()
394-
await mountWithAsyncData(`dedupedKey3-${count}`, () => Promise.resolve('test'))
394+
await mountWithAsyncData(`${uniqueKey}-${count}`, () => Promise.resolve('test'))
395395
expect(warn).toHaveBeenCalledWith(
396396
expect.stringMatching(
397-
new RegExp(`\\[nuxt\\] \\[useAsyncData\\] Incompatible options detected for "dedupedKey3-${count}" \\(used at .*:\\d+:\\d+\\):\n- different \`${opt}\` option\nYou can use a different key or move the call to a composable to ensure the options are shared across calls.`),
397+
new RegExp(`\\[nuxt\\] \\[useAsyncData\\] Incompatible options detected for "${uniqueKey}-${count}" \\(used at .*:\\d+:\\d+\\):\n- different \`${opt}\` option\nYou can use a different key or move the call to a composable to ensure the options are shared across calls.`),
398398
))
399399
}
400400

401401
warn.mockClear()
402402
count++
403403

404-
await mountWithAsyncData(`dedupedKey3-${count}`, () => Promise.resolve('test'))
404+
await mountWithAsyncData(`${uniqueKey}-${count}`, () => Promise.resolve('test'))
405405
expect(warn).not.toHaveBeenCalled()
406-
await mountWithAsyncData(`dedupedKey3-${count}`, () => Promise.resolve('bob'))
406+
await mountWithAsyncData(`${uniqueKey}-${count}`, () => Promise.resolve('bob'))
407407
expect(warn).toHaveBeenCalledWith(expect.stringMatching(
408-
new RegExp(`\\[nuxt\\] \\[useAsyncData\\] Incompatible options detected for "dedupedKey3-${count}" \\(used at .*:\\d+:\\d+\\):\n- different handler\nYou can use a different key or move the call to a composable to ensure the options are shared across calls.`),
408+
new RegExp(`\\[nuxt\\] \\[useAsyncData\\] Incompatible options detected for "${uniqueKey}-${count}" \\(used at .*:\\d+:\\d+\\):\n- different handler\nYou can use a different key or move the call to a composable to ensure the options are shared across calls.`),
409409
))
410410

411411
warn.mockReset()
@@ -714,9 +714,9 @@ describe('useAsyncData', () => {
714714
})
715715

716716
it('should not refetch on the client when hydrating', () => {
717-
useNuxtData('hydration-on-client').data.value = 'server-renderered'
717+
useNuxtData(uniqueKey).data.value = 'server-renderered'
718718
useNuxtApp().isHydrating = true
719-
const { data, status } = useAsyncData('hydration-on-client', () => Promise.resolve('test'))
719+
const { data, status } = useAsyncData(uniqueKey, () => Promise.resolve('test'))
720720
expect(data.value).toBe('server-renderered')
721721
expect(status.value).toBe('success')
722722
useNuxtApp().isHydrating = false

0 commit comments

Comments
 (0)