Skip to content

Commit 962af85

Browse files
authored
test(runtime-core): inject from closest ancestor (#2329)
1 parent 6df3675 commit 962af85

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed

packages/runtime-core/__tests__/apiOptions.spec.ts

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -888,6 +888,56 @@ describe('api: options', () => {
888888
expect(watchSpy.mock.calls[0].slice(0, 2)).toEqual(['hello', 'mixin3'])
889889
})
890890

891+
test('injection from closest ancestor', () => {
892+
const Root = defineComponent({
893+
provide: {
894+
a: 'root'
895+
},
896+
render() {
897+
return [h(Mid), ' ', h(MidWithProvide), ' ', h(MidWithMixinProvide)]
898+
}
899+
})
900+
901+
const Mid = {
902+
render() {
903+
return h(Child)
904+
}
905+
} as any
906+
907+
const MidWithProvide = {
908+
provide: {
909+
a: 'midWithProvide'
910+
},
911+
render() {
912+
return h(Child)
913+
}
914+
} as any
915+
916+
const mixin = {
917+
provide: {
918+
a: 'midWithMixinProvide'
919+
}
920+
}
921+
922+
const MidWithMixinProvide = {
923+
mixins: [mixin],
924+
render() {
925+
return h(Child)
926+
}
927+
} as any
928+
929+
const Child = {
930+
inject: ['a'],
931+
render() {
932+
return this.a
933+
}
934+
} as any
935+
936+
expect(renderToString(h(Root))).toBe(
937+
'root midWithProvide midWithMixinProvide'
938+
)
939+
})
940+
891941
describe('warnings', () => {
892942
test('Expected a function as watch handler', () => {
893943
const Comp = {

0 commit comments

Comments
 (0)