1
1
import { expect , describe , it } from 'vitest'
2
2
import { mount } from '@vue/test-utils'
3
+ import { defineAsyncComponent , defineComponent , h , markRaw } from 'vue'
3
4
import SanityContent from '../../src/runtime/components/sanity-content'
4
5
5
6
import * as exampleBlocks from './fixture/portable-text'
6
7
8
+ const CustomBlockComponent = defineComponent ( {
9
+ props : { exampleProp : String } ,
10
+ setup : ( props , { slots } ) => ( ) => h ( 'div' , { } , {
11
+ default : ( ) => [
12
+ props . exampleProp ,
13
+ slots . default ?.( ) ,
14
+ ] ,
15
+ } ) ,
16
+ } )
17
+
7
18
describe ( 'SanityContent' , ( ) => {
8
19
it ( 'should render with no props' , ( ) => {
9
20
const wrapper = mount ( SanityContent )
@@ -15,9 +26,20 @@ describe('SanityContent', () => {
15
26
const wrapper = mount ( SanityContent as any , {
16
27
props : {
17
28
blocks : Array . isArray ( block ) ? block : [ block ] ,
18
- serializers : {
19
- types : { customIcon : 'i' } ,
20
- } ,
29
+ serializers : markRaw ( {
30
+ types : {
31
+ customIcon : 'i' ,
32
+ // This is how to access a component registered by `@nuxt/components`
33
+ customComponent1 : CustomBlockComponent ,
34
+ // A directly imported component
35
+ customComponent2 : CustomBlockComponent ,
36
+ // Example of a more complex async component
37
+ customComponent3 : defineAsyncComponent ( {
38
+ loadingComponent : ( ) => h ( 'div' , 'Loading...' ) ,
39
+ loader : ( ) => Promise . resolve ( CustomBlockComponent ) ,
40
+ } ) ,
41
+ } ,
42
+ } ) ,
21
43
} ,
22
44
} )
23
45
expect ( wrapper . html ( ) ) . toMatchSnapshot ( )
0 commit comments