From 593b86636a072a5e82744763b85e9f977b35b4b6 Mon Sep 17 00:00:00 2001 From: Eduardo San Martin Morote Date: Fri, 9 Mar 2018 11:02:22 +0100 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20support=20pending=20named=20slot=20?= =?UTF-8?q?(same=20as=20non-scoped=20default)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/index.js | 7 ++++--- test/index.spec.js | 14 ++++++++++++++ test/utils/NamedSlots.vue | 17 +++++++++++++++++ 3 files changed, 35 insertions(+), 3 deletions(-) create mode 100644 test/utils/NamedSlots.vue diff --git a/src/index.js b/src/index.js index 0bb2966..1517fe2 100644 --- a/src/index.js +++ b/src/index.js @@ -28,10 +28,11 @@ export default { return this.$scopedSlots.default(this.data) } else { assert( - this.$slots.default && this.$slots.default.length === 1, - 'Provide exactly one default slot with no `slot-scope` for the pending promise' + (this.$slots.default && this.$slots.default.length === 1) || + (this.$slots.pending && this.$slots.pending.length === 1), + 'Provide exactly one default/pending slot with no `slot-scope` for the pending promise' ) - return this.$slots.default[0] + return this.$slots.default ? this.$slots.default[0] : this.$slots.pending[0] } }, diff --git a/test/index.spec.js b/test/index.spec.js index 17403c7..b11cef9 100644 --- a/test/index.spec.js +++ b/test/index.spec.js @@ -1,6 +1,7 @@ import { mount } from '@vue/test-utils' import fakePromise from 'faked-promise' import Helper from './utils/Helper' +import NamedSlots from './utils/NamedSlots' import NoError from './utils/NoError' import NoResolve from './utils/NoResolve' import NoPending from './utils/NoPending' @@ -162,4 +163,17 @@ describe('Promised', () => { expect(errorSpy).toHaveBeenCalledTimes(2) }) }) + + describe('slots names', () => { + let promise, resolve, reject + beforeEach(() => { + [promise, resolve, reject] = fakePromise() + wrapper = mount(NamedSlots, { + propsData: { promise }, + }) + }) + test('supports named pending slot', () => { + expect(wrapper.text()).toBe('loading') + }) + }) }) diff --git a/test/utils/NamedSlots.vue b/test/utils/NamedSlots.vue new file mode 100644 index 0000000..25ae1e3 --- /dev/null +++ b/test/utils/NamedSlots.vue @@ -0,0 +1,17 @@ + + +