Skip to content

Commit

Permalink
✨ support pending named slot (same as non-scoped default)
Browse files Browse the repository at this point in the history
  • Loading branch information
posva committed Mar 9, 2018
1 parent 1b6bc11 commit 593b866
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]
}
},

Expand Down
14 changes: 14 additions & 0 deletions test/index.spec.js
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -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')
})
})
})
17 changes: 17 additions & 0 deletions test/utils/NamedSlots.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<template>
<Promised v-bind="$props">
<h1 slot="pending">loading</h1>
<!-- The default scoped slots will be used as the result -->
<h1 slot="then" slot-scope="data">{{ data | text }}</h1>
<!-- The 'error' named scoped slots will be used if there is an error -->
<h1 slot="catch" slot-scope="error">{{ error | errorText }}</h1>
</Promised>
</template>

<script>
import common from './common'
export default {
mixins: [common],
}
</script>

0 comments on commit 593b866

Please sign in to comment.