8000 test: add regression test for useAsyncData + transition · nuxt/nuxt@29f7c8c · GitHub
[go: up one dir, main page]

Skip to content

Commit 29f7c8c

Browse files
committed
test: add regression test for useAsyncData + transition
#32096
1 parent 2954c09 commit 29f7c8c

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

test/nuxt/composables.test.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { mountSuspended, registerEndpoint } from '@nuxt/test-utils/runtime'
88

99
import { hasProtocol, withQuery } from 'ufo'
1010
import { flushPromises } from '@vue/test-utils'
11+
import { Transition } from 'vue'
1112
import { createClientPage } from '../../packages/nuxt/src/components/runtime/client-component'
1213
import * as composables from '#app/composables'
1314

@@ -648,6 +649,39 @@ describe('useAsyncData', () => {
648649
expect(nuxtData.value).toMatchInlineSnapshot('"another value"')
649650
})
650651

652+
it('should work when used in a Transition', async () => {
653+
const id = ref('foo')
654+
const ComponentWithAsyncData = defineComponent({
655+
props: { id: String },
656+
async setup (props) {
657+
const { data } = await useAsyncData(`quote:${props.id}`, () => Promise.resolve({ content: props.id }))
658+
return () => h('div', data.value?.content)
659+
},
660+
})
661+
const ComponentWithTransition = defineComponent({
662+
setup: () => () => h(Transition, { name: 'test' }, {
663+
default: () => h(ComponentWithAsyncData, { id: id.value, key: id.value }),
664+
}),
665+
})
666+
async function setTo (newId: string) {
667+
id.value = newId
668+
for (let i = 0; i < 5; i++) {
669+
await nextTick()
670+
await flushPromises()
671+
}
672+
}
673+
674+
const wrapper = await mountSuspended(ComponentWithTransition, { global: { stubs: { transition: false } } })
675+
await setTo('foo')
676+
expect(wrapper.html()).toMatchInlineSnapshot(`"<div>foo</div>"`)
677+
678+
await setTo('bar')
679+
expect(wrapper.html()).toMatchInlineSnapshot(`"<div class="">bar</div>"`)
680+
681+
await setTo('foo')
682+
expect(wrapper.html()).toMatchInlineSnapshot(`"<div class="">foo</div>"`)
683+
})
684+
651685
it('duplicate calls are not made after first call has finished', async () => {
652686
const handler = vi.fn(() => Promise.resolve('hello'))
653687
const getCachedData = vi.fn((key: string, nuxtApp: NuxtApp) => {

0 commit comments

Comments
 (0)
0