@@ -8,6 +8,7 @@ import { mountSuspended, registerEndpoint } from '@nuxt/test-utils/runtime'
8
8
9
9
import { hasProtocol , withQuery } from 'ufo'
10
10
import { flushPromises } from '@vue/test-utils'
11
+ import { Transition } from 'vue'
11
12
import { createClientPage } from '../../packages/nuxt/src/components/runtime/client-component'
12
13
import * as composables from '#app/composables'
13
14
@@ -648,6 +649,39 @@ describe('useAsyncData', () => {
648
649
expect ( nuxtData . value ) . toMatchInlineSnapshot ( '"another value"' )
649
650
} )
650
651
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
+
651
685
it ( 'duplicate calls are not made after first call has finished' , async ( ) => {
652
686
const handler = vi . fn ( ( ) => Promise . resolve ( 'hello' ) )
653
687
const getCachedData = vi . fn ( ( key : string , nuxtApp : NuxtApp ) => {
0 commit comments