diff --git a/lerna.json b/lerna.json index 1353e8b6a..f37ea2774 100644 --- a/lerna.json +++ b/lerna.json @@ -5,5 +5,5 @@ ], "npmClient": "yarn", "useWorkspaces": true, - "version": "1.3.5" + "version": "1.3.6" } diff --git a/packages/create-instance/create-component-stubs.js b/packages/create-instance/create-component-stubs.js index aa29e0012..00780c9d4 100644 --- a/packages/create-instance/create-component-stubs.js +++ b/packages/create-instance/create-component-stubs.js @@ -77,16 +77,8 @@ function getScopedSlotRenderFunctions(ctx: any): Array { // In Vue 2.6+ a new v-slot syntax was introduced // scopedSlots are now saved in parent._vnode.data.scopedSlots // We filter out _normalized, $stable and $key keys - if ( - ctx && - ctx.$options && - ctx.$options.parent && - ctx.$options.parent._vnode && - ctx.$options.parent._vnode.data && - ctx.$options.parent._vnode.data.scopedSlots - ) { - const slotKeys: Array = ctx.$options.parent._vnode.data.scopedSlots - return keys(slotKeys).filter( + if (ctx.$vnode.data.scopedSlots) { + return keys(ctx.$vnode.data.scopedSlots).filter( x => x !== '_normalized' && x !== '$stable' && x !== '$key' ) } @@ -130,9 +122,15 @@ export function createStubFromComponent( context ? context.children : this.$options._renderChildren || - getScopedSlotRenderFunctions(this).map(x => - this.$options.parent._vnode.data.scopedSlots[x]({}) - ) + getScopedSlotRenderFunctions(this) + .map(x => { + let result = null + try { + result = this.$vnode.data.scopedSlots[x]({}) + } catch (e) {} + return result + }) + .filter(Boolean) ) } } diff --git a/packages/server-test-utils/dist/vue-server-test-utils.js b/packages/server-test-utils/dist/vue-server-test-utils.js index cf5f0a217..3f79fd4a8 100644 --- a/packages/server-test-utils/dist/vue-server-test-utils.js +++ b/packages/server-test-utils/dist/vue-server-test-utils.js @@ -13507,16 +13507,8 @@ function getScopedSlotRenderFunctions(ctx) { // In Vue 2.6+ a new v-slot syntax was introduced // scopedSlots are now saved in parent._vnode.data.scopedSlots // We filter out _normalized, $stable and $key keys - if ( - ctx && - ctx.$options && - ctx.$options.parent && - ctx.$options.parent._vnode && - ctx.$options.parent._vnode.data && - ctx.$options.parent._vnode.data.scopedSlots - ) { - var slotKeys = ctx.$options.parent._vnode.data.scopedSlots; - return keys$1(slotKeys).filter( + if (ctx.$vnode.data.scopedSlots) { + return keys$1(ctx.$vnode.data.scopedSlots).filter( function (x) { return x !== '_normalized' && x !== '$stable' && x !== '$key'; } ) } @@ -13555,8 +13547,15 @@ function createStubFromComponent( context ? context.children : this.$options._renderChildren || - getScopedSlotRenderFunctions(this).map(function (x) { return this$1.$options.parent._vnode.data.scopedSlots[x]({}); } - ) + getScopedSlotRenderFunctions(this) + .map(function (x) { + var result = null; + try { + result = this$1.$vnode.data.scopedSlots[x]({}); + } catch (e) {} + return result + }) + .filter(Boolean) ) }}) } diff --git a/packages/server-test-utils/package.json b/packages/server-test-utils/package.json index ddabb64ee..72f4f4e6a 100644 --- a/packages/server-test-utils/package.json +++ b/packages/server-test-utils/package.json @@ -1,6 +1,6 @@ { "name": "@vue/server-test-utils", - "version": "1.3.5", + "version": "1.3.6", "description": "Utilities for testing Vue components.", "main": "dist/vue-server-test-utils.js", "types": "types/index.d.ts", diff --git a/packages/test-utils/dist/vue-test-utils.esm.js b/packages/test-utils/dist/vue-test-utils.esm.js index 3761009fb..9e1e88d1b 100644 --- a/packages/test-utils/dist/vue-test-utils.esm.js +++ b/packages/test-utils/dist/vue-test-utils.esm.js @@ -2295,16 +2295,8 @@ function getScopedSlotRenderFunctions(ctx) { // In Vue 2.6+ a new v-slot syntax was introduced // scopedSlots are now saved in parent._vnode.data.scopedSlots // We filter out _normalized, $stable and $key keys - if ( - ctx && - ctx.$options && - ctx.$options.parent && - ctx.$options.parent._vnode && - ctx.$options.parent._vnode.data && - ctx.$options.parent._vnode.data.scopedSlots - ) { - var slotKeys = ctx.$options.parent._vnode.data.scopedSlots; - return keys(slotKeys).filter( + if (ctx.$vnode.data.scopedSlots) { + return keys(ctx.$vnode.data.scopedSlots).filter( function (x) { return x !== '_normalized' && x !== '$stable' && x !== '$key'; } ) } @@ -2343,8 +2335,15 @@ function createStubFromComponent( context ? context.children : this.$options._renderChildren || - getScopedSlotRenderFunctions(this).map(function (x) { return this$1.$options.parent._vnode.data.scopedSlots[x]({}); } - ) + getScopedSlotRenderFunctions(this) + .map(function (x) { + var result = null; + try { + result = this$1.$vnode.data.scopedSlots[x]({}); + } catch (e) {} + return result + }) + .filter(Boolean) ) }}) } diff --git a/packages/test-utils/dist/vue-test-utils.iife.js b/packages/test-utils/dist/vue-test-utils.iife.js index 9be5829e2..240af9397 100644 --- a/packages/test-utils/dist/vue-test-utils.iife.js +++ b/packages/test-utils/dist/vue-test-utils.iife.js @@ -2299,16 +2299,8 @@ var VueTestUtils = (function (exports, Vue, vueTemplateCompiler) { // In Vue 2.6+ a new v-slot syntax was introduced // scopedSlots are now saved in parent._vnode.data.scopedSlots // We filter out _normalized, $stable and $key keys - if ( - ctx && - ctx.$options && - ctx.$options.parent && - ctx.$options.parent._vnode && - ctx.$options.parent._vnode.data && - ctx.$options.parent._vnode.data.scopedSlots - ) { - var slotKeys = ctx.$options.parent._vnode.data.scopedSlots; - return keys(slotKeys).filter( + if (ctx.$vnode.data.scopedSlots) { + return keys(ctx.$vnode.data.scopedSlots).filter( function (x) { return x !== '_normalized' && x !== '$stable' && x !== '$key'; } ) } @@ -2347,8 +2339,15 @@ var VueTestUtils = (function (exports, Vue, vueTemplateCompiler) { context ? context.children : this.$options._renderChildren || - getScopedSlotRenderFunctions(this).map(function (x) { return this$1.$options.parent._vnode.data.scopedSlots[x]({}); } - ) + getScopedSlotRenderFunctions(this) + .map(function (x) { + var result = null; + try { + result = this$1.$vnode.data.scopedSlots[x]({}); + } catch (e) {} + return result + }) + .filter(Boolean) ) }}) } diff --git a/packages/test-utils/dist/vue-test-utils.js b/packages/test-utils/dist/vue-test-utils.js index 008baaeb1..01d1d82f1 100644 --- a/packages/test-utils/dist/vue-test-utils.js +++ b/packages/test-utils/dist/vue-test-utils.js @@ -2303,16 +2303,8 @@ function getScopedSlotRenderFunctions(ctx) { // In Vue 2.6+ a new v-slot syntax was introduced // scopedSlots are now saved in parent._vnode.data.scopedSlots // We filter out _normalized, $stable and $key keys - if ( - ctx && - ctx.$options && - ctx.$options.parent && - ctx.$options.parent._vnode && - ctx.$options.parent._vnode.data && - ctx.$options.parent._vnode.data.scopedSlots - ) { - var slotKeys = ctx.$options.parent._vnode.data.scopedSlots; - return keys(slotKeys).filter( + if (ctx.$vnode.data.scopedSlots) { + return keys(ctx.$vnode.data.scopedSlots).filter( function (x) { return x !== '_normalized' && x !== '$stable' && x !== '$key'; } ) } @@ -2351,8 +2343,15 @@ function createStubFromComponent( context ? context.children : this.$options._renderChildren || - getScopedSlotRenderFunctions(this).map(function (x) { return this$1.$options.parent._vnode.data.scopedSlots[x]({}); } - ) + getScopedSlotRenderFunctions(this) + .map(function (x) { + var result = null; + try { + result = this$1.$vnode.data.scopedSlots[x]({}); + } catch (e) {} + return result + }) + .filter(Boolean) ) }}) } diff --git a/packages/test-utils/dist/vue-test-utils.umd.js b/packages/test-utils/dist/vue-test-utils.umd.js index 4f9afe3e5..68cd841ab 100644 --- a/packages/test-utils/dist/vue-test-utils.umd.js +++ b/packages/test-utils/dist/vue-test-utils.umd.js @@ -2302,16 +2302,8 @@ // In Vue 2.6+ a new v-slot syntax was introduced // scopedSlots are now saved in parent._vnode.data.scopedSlots // We filter out _normalized, $stable and $key keys - if ( - ctx && - ctx.$options && - ctx.$options.parent && - ctx.$options.parent._vnode && - ctx.$options.parent._vnode.data && - ctx.$options.parent._vnode.data.scopedSlots - ) { - var slotKeys = ctx.$options.parent._vnode.data.scopedSlots; - return keys(slotKeys).filter( + if (ctx.$vnode.data.scopedSlots) { + return keys(ctx.$vnode.data.scopedSlots).filter( function (x) { return x !== '_normalized' && x !== '$stable' && x !== '$key'; } ) } @@ -2350,8 +2342,15 @@ context ? context.children : this.$options._renderChildren || - getScopedSlotRenderFunctions(this).map(function (x) { return this$1.$options.parent._vnode.data.scopedSlots[x]({}); } - ) + getScopedSlotRenderFunctions(this) + .map(function (x) { + var result = null; + try { + result = this$1.$vnode.data.scopedSlots[x]({}); + } catch (e) {} + return result + }) + .filter(Boolean) ) }}) } diff --git a/packages/test-utils/package.json b/packages/test-utils/package.json index 4831c0dd3..334e01e9d 100644 --- a/packages/test-utils/package.json +++ b/packages/test-utils/package.json @@ -1,6 +1,6 @@ { "name": "@vue/test-utils", - "version": "1.3.5", + "version": "1.3.6", "description": "Utilities for testing Vue components.", "main": "dist/vue-test-utils.js", "module": "dist/vue-test-utils.esm.js", diff --git a/test/specs/shallow-mount.spec.js b/test/specs/shallow-mount.spec.js index a487e76a3..551ea7943 100644 --- a/test/specs/shallow-mount.spec.js +++ b/test/specs/shallow-mount.spec.js @@ -164,6 +164,38 @@ describeRunIf(process.env.TEST_ENV !== 'node', 'shallowMount', () => { ) }) + it('renders named slots with v-slot syntax when they are wrapped', () => { + const localVue = createLocalVue() + localVue.component('Foo', { + template: '
' + }) + const TestComponent = { + template: ` +
+ + + +
+ ` + } + const wrapper = shallowMount(TestComponent, { + localVue + }) + expect(wrapper.find({ name: 'Foo' }).exists()).toEqual(true) + expect(wrapper.find('.new-example').exists()).toEqual(true) + expect(wrapper.html()).toEqual( + [ + '
', + ' ', + '

text

', + '
', + '
' + ].join('\n') + ) + }) + it('renders named slots when they are located inside component with v-if', () => { const localVue = createLocalVue() localVue.component('Foo', {