Skip to content
This repository was archived by the owner on Jul 19, 2025. It is now read-only.

Commit 598b55f

Browse files
committed
test(runtime-vapor): finish expose and inject tests
1 parent bbd1944 commit 598b55f

File tree

3 files changed

+36
-27
lines changed

3 files changed

+36
-27
lines changed

packages/runtime-vapor/__tests__/apiExpose.spec.ts

Lines changed: 31 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,12 @@ import {
66
type ComponentInternalInstance,
77
getCurrentInstance,
88
} from '../src/component'
9+
import { defineComponent } from '../src/apiDefineComponent'
910

1011
const define = makeRender()
1112
describe('api: expose', () => {
1213
test('via setup context', () => {
13-
const { component: Child } = define({
14+
const Child = defineComponent({
1415
setup(_, { expose }) {
1516
expose({
1617
foo: 1,
@@ -23,15 +24,14 @@ describe('api: expose', () => {
2324
},
2425
})
2526
const childRef = ref()
26-
const { render } = define({
27+
define({
2728
render: () => {
2829
const n0 = createComponent(Child)
2930
setRef(n0, childRef)
3031
return n0
3132
},
32-
})
33+
}).render()
3334

34-
render()
3535
expect(childRef.value).toBeTruthy()
3636
expect(childRef.value.foo).toBe(1)
3737
expect(childRef.value.bar).toBe(2)
@@ -40,56 +40,70 @@ describe('api: expose', () => {
4040

4141
test('via setup context (expose empty)', () => {
4242
let childInstance: ComponentInternalInstance | null = null
43-
const { component: Child } = define({
43+
const Child = defineComponent({
4444
setup(_) {
4545
childInstance = getCurrentInstance()
4646
},
4747
})
4848
const childRef = shallowRef()
49-
const { render } = define({
49+
define({
5050
render: () => {
5151
const n0 = createComponent(Child)
5252
setRef(n0, childRef)
5353
return n0
5454
},
55-
})
55+
}).render()
5656

57-
render()
5857
expect(childInstance!.exposed).toBeUndefined()
5958
expect(childRef.value).toBe(childInstance!)
6059
})
6160

61+
test('with mount', () => {
62+
const { instance } = define({
63+
setup(_, { expose }) {
64+
expose({
65+
foo: 1,
66+
})
67+
return {
68+
bar: 2,
69+
}
70+
},
71+
}).render()
72+
expect(instance!.exposed!.foo).toBe(1)
73+
expect(instance!.exposed!.bar).toBe(undefined)
74+
})
75+
6276
test('warning for ref', () => {
63-
const { render } = define({
77+
define({
6478
setup(_, { expose }) {
6579
expose(ref(1))
6680
},
67-
})
68-
render()
81+
}).render()
82+
6983
expect(
7084
'expose() should be passed a plain object, received ref',
7185
).toHaveBeenWarned()
7286
})
7387

7488
test('warning for array', () => {
75-
const { render } = define({
89+
define({
7690
setup(_, { expose }) {
7791
expose(['focus'])
7892
},
79-
})
80-
render()
93+
}).render()
94+
8195
expect(
8296
'expose() should be passed a plain object, received array',
8397
).toHaveBeenWarned()
8498
})
8599

86100
test('warning for function', () => {
87-
const { render } = define({
101+
define({
88102
setup(_, { expose }) {
89103
expose(() => null)
90104
},
91-
})
92-
render()
105+
}).render()
106+
93107
expect(
94108
'expose() should be passed a plain object, received function',
95109
).toHaveBeenWarned()

packages/runtime-vapor/__tests__/apiInject.spec.ts

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
// NOTE: This test is implemented based on the case of `runtime-core/__test__/apiInject.spec.ts`.
2-
31
import {
42
type InjectionKey,
53
type Ref,
@@ -356,17 +354,15 @@ describe('api: provide/inject', () => {
356354
})
357355

358356
// #2400
359-
it.todo('should not self-inject', () => {
360-
const Comp = define({
357+
it('should not self-inject', () => {
358+
const { host } = define({
361359
setup() {
362360
provide('foo', 'foo')
363361
const injection = inject('foo', null)
364-
return () => injection
362+
return createTextNode(() => [injection])
365363
},
366-
})
367-
368-
Comp.render()
369-
expect(Comp.host.innerHTML).toBe('')
364+
}).render()
365+
expect(host.innerHTML).toBe('')
370366
})
371367

372368
describe('hasInjectionContext', () => {

packages/runtime-vapor/src/component.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,6 @@ export interface ComponentInternalInstance {
186186

187187
attrsProxy?: Data
188188
slotsProxy?: Slots
189-
exposeProxy?: Record<string, any>
190189

191190
// lifecycle
192191
isMounted: boolean

0 commit comments

Comments
 (0)