File tree 2 files changed +24
-3
lines changed
2 files changed +24
-3
lines changed Original file line number Diff line number Diff line change 1
- import { nodeOps , render } from '@vue/runtime-test'
1
+ import { createApp , nodeOps , render } from '@vue/runtime-test'
2
2
import { defineComponent , h , ref } from '../src'
3
3
4
4
describe ( 'api: expose' , ( ) => {
@@ -170,6 +170,26 @@ describe('api: expose', () => {
170
170
render ( h ( Parent ) , root )
171
171
} )
172
172
173
+ test ( 'with mount' , ( ) => {
174
+ const Component = defineComponent ( {
175
+ setup ( _ , { expose } ) {
176
+ expose ( {
177
+ foo : 1
178
+ } )
179
+ return {
180
+ bar : 2
181
+ }
182
+ } ,
183
+ render ( ) {
184
+ return h ( 'div' )
185
+ }
186
+ } )
187
+ const root = nodeOps . createElement ( 'div' )
188
+ const vm = createApp ( Component ) . mount ( root ) as any
189
+ expect ( vm . foo ) . toBe ( 1 )
190
+ expect ( vm . bar ) . toBe ( undefined )
191
+ } )
192
+
173
193
test ( 'expose should allow access to built-in instance properties' , ( ) => {
174
194
const GrandChild = defineComponent ( {
175
195
render ( ) {
Original file line number Diff line number Diff line change 3
3
Data ,
4
4
validateComponentName ,
5
5
Component ,
6
- ComponentInternalInstance
6
+ ComponentInternalInstance ,
7
+ getExposeProxy
7
8
} from './component'
8
9
import {
9
10
ComponentOptions ,
@@ -309,7 +310,7 @@ export function createAppAPI<HostElement>(
309
310
devtoolsInitApp ( app , version )
310
311
}
311
312
312
- return vnode . component ! . proxy
313
+ return getExposeProxy ( vnode . component ! ) || vnode . component ! . proxy
313
314
} else if ( __DEV__ ) {
314
315
warn (
315
316
`App has already been mounted.\n` +
You can’t perform that action at this time.
0 commit comments