File tree Expand file tree Collapse file tree 2 files changed +60
-2
lines changed
packages/runtime-vapor/__tests__ Expand file tree Collapse file tree 2 files changed +60
-2
lines changed Original file line number Diff line number Diff line change 11import {
22 type InjectionKey ,
33 type Ref ,
4+ h ,
45 hasInjectionContext ,
56 inject ,
67 nextTick ,
@@ -17,6 +18,7 @@ import {
1718 createVaporApp ,
1819 defineVaporComponent ,
1920 renderEffect ,
21+ vaporInteropPlugin ,
2022 withVaporCtx ,
2123} from '../src'
2224import { makeRender } from './_utils'
@@ -422,3 +424,34 @@ describe('api: provide/inject', () => {
422424 } )
423425 } )
424426} )
427+
428+ describe ( 'vdom interop' , ( ) => {
429+ test ( 'should inject value from vapor parent' , async ( ) => {
430+ const VdomChild = {
431+ setup ( ) {
432+ const foo = inject ( 'foo' )
433+ return ( ) => h ( 'div' , null , [ toDisplayString ( foo ) ] )
434+ } ,
435+ }
436+
437+ const value = ref ( 'foo' )
438+ const App = defineVaporComponent ( {
439+ setup ( ) {
440+ provide ( 'foo' , value )
441+ return createComponent ( VdomChild as any )
442+ } ,
443+ } )
444+
445+ const root = document . createElement ( 'div' )
446+ document . body . appendChild ( root )
447+ const app = createVaporApp ( App )
448+ app . use ( vaporInteropPlugin )
449+ app . mount ( root )
450+
451+ expect ( root . innerHTML ) . toBe ( '<div>foo</div>' )
452+
453+ value . value = 'bar'
454+ await nextTick ( )
455+ expect ( root . innerHTML ) . toBe ( '<div>bar</div>' )
456+ } )
457+ } )
Original file line number Diff line number Diff line change @@ -3,12 +3,14 @@ import {
33 createVNode ,
44 defineComponent ,
55 h ,
6+ inject ,
67 nextTick ,
78 onActivated ,
89 onBeforeMount ,
910 onDeactivated ,
1011 onMounted ,
1112 onUnmounted ,
13+ provide ,
1214 ref ,
1315 renderSlot ,
1416 toDisplayString ,
@@ -234,9 +236,32 @@ describe('vdomInterop', () => {
234236 } )
235237 } )
236238
237- describe . todo ( 'provide' , ( ) => { } )
239+ describe ( 'provide / inject' , ( ) => {
240+ it ( 'should inject value from vdom parent' , async ( ) => {
241+ const VaporChild = defineVaporComponent ( {
242+ setup ( ) {
243+ const foo = inject ( 'foo' )
244+ const n0 = template ( ' ' ) ( ) as any
245+ renderEffect ( ( ) => setText ( n0 , toDisplayString ( foo ) ) )
246+ return n0
247+ } ,
248+ } )
249+
250+ const value = ref ( 'foo' )
251+ const { html } = define ( {
252+ setup ( ) {
253+ provide ( 'foo' , value )
254+ return ( ) => h ( VaporChild as any )
255+ } ,
256+ } ) . render ( )
257+
258+ expect ( html ( ) ) . toBe ( 'foo' )
238259
239- describe . todo ( 'inject' , ( ) => { } )
260+ value . value = 'bar'
261+ await nextTick ( )
262+ expect ( html ( ) ) . toBe ( 'bar' )
263+ } )
264+ } )
240265
241266 describe . todo ( 'template ref' , ( ) => { } )
242267
You can’t perform that action at this time.
0 commit comments