From: Hunter Date: Tue, 13 Oct 2020 20:31:13 +0000 (+0800) Subject: test(runtime-core): inject from closest ancestor (#2329) X-Git-Tag: v3.0.1~11 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=962af852207b56239fcb0d2f8e68549ad59fb8d4;p=thirdparty%2Fvuejs%2Fcore.git test(runtime-core): inject from closest ancestor (#2329) --- diff --git a/packages/runtime-core/__tests__/apiOptions.spec.ts b/packages/runtime-core/__tests__/apiOptions.spec.ts index ad2c7106a8..ab60ac7ca8 100644 --- a/packages/runtime-core/__tests__/apiOptions.spec.ts +++ b/packages/runtime-core/__tests__/apiOptions.spec.ts @@ -888,6 +888,56 @@ describe('api: options', () => { expect(watchSpy.mock.calls[0].slice(0, 2)).toEqual(['hello', 'mixin3']) }) + test('injection from closest ancestor', () => { + const Root = defineComponent({ + provide: { + a: 'root' + }, + render() { + return [h(Mid), ' ', h(MidWithProvide), ' ', h(MidWithMixinProvide)] + } + }) + + const Mid = { + render() { + return h(Child) + } + } as any + + const MidWithProvide = { + provide: { + a: 'midWithProvide' + }, + render() { + return h(Child) + } + } as any + + const mixin = { + provide: { + a: 'midWithMixinProvide' + } + } + + const MidWithMixinProvide = { + mixins: [mixin], + render() { + return h(Child) + } + } as any + + const Child = { + inject: ['a'], + render() { + return this.a + } + } as any + + expect(renderToString(h(Root))).toBe( + 'root midWithProvide midWithMixinProvide' + ) + }) + describe('warnings', () => { test('Expected a function as watch handler', () => { const Comp = {