|
|
@@ -502,5 +502,64 @@ describe('component: slots', () => {
|
|
|
await nextTick()
|
|
|
expect(host.innerHTML).toBe('<div><h1></h1><!--slot--></div>')
|
|
|
})
|
|
|
+
|
|
|
+ test('render fallback when slot content is not valid', async () => {
|
|
|
+ const Child = {
|
|
|
+ setup() {
|
|
|
+ return createSlot('default', null, () =>
|
|
|
+ document.createTextNode('fallback'),
|
|
|
+ )
|
|
|
+ },
|
|
|
+ }
|
|
|
+
|
|
|
+ const { html } = define({
|
|
|
+ setup() {
|
|
|
+ return createComponent(Child, null, {
|
|
|
+ default: () => {
|
|
|
+ return template('<!--comment-->')()
|
|
|
+ },
|
|
|
+ })
|
|
|
+ },
|
|
|
+ }).render()
|
|
|
+
|
|
|
+ expect(html()).toBe('fallback<!--slot-->')
|
|
|
+ })
|
|
|
+
|
|
|
+ test('render fallback when v-if condition is false', async () => {
|
|
|
+ const Child = {
|
|
|
+ setup() {
|
|
|
+ return createSlot('default', null, () =>
|
|
|
+ document.createTextNode('fallback'),
|
|
|
+ )
|
|
|
+ },
|
|
|
+ }
|
|
|
+
|
|
|
+ const toggle = ref(false)
|
|
|
+
|
|
|
+ const { html } = define({
|
|
|
+ setup() {
|
|
|
+ return createComponent(Child, null, {
|
|
|
+ default: () => {
|
|
|
+ return createIf(
|
|
|
+ () => toggle.value,
|
|
|
+ () => {
|
|
|
+ return document.createTextNode('content')
|
|
|
+ },
|
|
|
+ )
|
|
|
+ },
|
|
|
+ })
|
|
|
+ },
|
|
|
+ }).render()
|
|
|
+
|
|
|
+ expect(html()).toBe('fallback<!--if--><!--slot-->')
|
|
|
+
|
|
|
+ toggle.value = true
|
|
|
+ await nextTick()
|
|
|
+ expect(html()).toBe('content<!--if--><!--slot-->')
|
|
|
+
|
|
|
+ toggle.value = false
|
|
|
+ await nextTick()
|
|
|
+ expect(html()).toBe('fallback<!--if--><!--slot-->')
|
|
|
+ })
|
|
|
})
|
|
|
})
|