From 7b576f66c2b2ca2263d9bf3b16c731e746c38e3a Mon Sep 17 00:00:00 2001 From: Lachlan Miller Date: Fri, 11 Sep 2020 09:51:40 +1000 Subject: [PATCH 1/2] fix: trim slot when passed a string --- src/mount.ts | 2 +- tests/mountingOptions/slots.spec.ts | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/mount.ts b/src/mount.ts index 7183a8021..00e4749e2 100644 --- a/src/mount.ts +++ b/src/mount.ts @@ -236,7 +236,7 @@ export function mount( if (typeof slot === 'string') { // slot is most probably a scoped slot string or a plain string - acc[name] = (props: VNodeProps) => h(processSlot(slot), props) + acc[name] = (props: VNodeProps) => h(processSlot(slot.trim()), props) return acc } diff --git a/tests/mountingOptions/slots.spec.ts b/tests/mountingOptions/slots.spec.ts index b052383f6..1a9e65be4 100644 --- a/tests/mountingOptions/slots.spec.ts +++ b/tests/mountingOptions/slots.spec.ts @@ -141,9 +141,13 @@ describe('slots', () => { }) it('allows passing a scoped slot via string with no destructuring using the v-slot syntax ', () => { + // Note: there is intentionally a carriage return after the first ` in the scoped key. + // https://github.com/vuejs/vue-test-utils-next/issues/202 const wrapper = mount(ComponentWithSlots, { slots: { - scoped: `` + scoped: ` + + ` } }) From 7b4a8035a79c257c07de1f2c8bcb5b790c6a1fad Mon Sep 17 00:00:00 2001 From: Lachlan Miller Date: Fri, 11 Sep 2020 17:46:21 +1000 Subject: [PATCH 2/2] refactor: move trim to process function --- src/mount.ts | 2 +- src/utils/compileSlots.ts | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/mount.ts b/src/mount.ts index 00e4749e2..7183a8021 100644 --- a/src/mount.ts +++ b/src/mount.ts @@ -236,7 +236,7 @@ export function mount( if (typeof slot === 'string') { // slot is most probably a scoped slot string or a plain string - acc[name] = (props: VNodeProps) => h(processSlot(slot.trim()), props) + acc[name] = (props: VNodeProps) => h(processSlot(slot), props) return acc } diff --git a/src/utils/compileSlots.ts b/src/utils/compileSlots.ts index 90d715acd..f0f12a6d7 100644 --- a/src/utils/compileSlots.ts +++ b/src/utils/compileSlots.ts @@ -1,7 +1,8 @@ import { compile } from '@vue/compiler-dom' import * as vue from 'vue' -export function processSlot(template = '', Vue = vue) { +export function processSlot(source = '', Vue = vue) { + let template = source.trim() const hasWrappingTemplate = template && template.startsWith('