Skip to content

Commit

Permalink
chore: add test case
Browse files Browse the repository at this point in the history
  • Loading branch information
yangchangtao committed Oct 18, 2024
1 parent 4b1b14e commit e8e3cdf
Showing 1 changed file with 54 additions and 8 deletions.
62 changes: 54 additions & 8 deletions packages/runtime-core/__tests__/componentSlots.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -345,20 +345,43 @@ describe('component: slots', () => {
).toHaveBeenWarned()
})

test('basic warn when mounting another app in setup', () => {
const Comp = {
setup(_: any, { slots }: any) {
slots.default?.()
return () => null
},
}

const mountComp = () => {
createApp({
setup() {
return () => h(Comp, () => 'msg')
},
}).mount(nodeOps.createElement('div'))
}

const App = {
setup() {
mountComp()
return () => null
},
}

createApp(App).mount(nodeOps.createElement('div'))
expect(
'Slot "default" invoked outside of the render function',
).toHaveBeenWarned()
})

test('should not warn when render in setup', () => {
const container = {
setup(_: any, { slots }: any) {
return function () {
return slots.default && slots.default()
}
return () => slots.default && slots.default()
},
}

const comp = h(container, null, {
default() {
return () => h('div')
},
})
const comp = h(container, null, () => h('div'))

const App = {
setup() {
Expand All @@ -372,4 +395,27 @@ describe('component: slots', () => {
'Slot "default" invoked outside of the render function',
).not.toHaveBeenWarned()
})

test('basic warn when render in setup', () => {
const container = {
setup(_: any, { slots }: any) {
slots.default && slots.default()
return () => null
},
}

const comp = h(container, null, () => h('div'))

const App = {
setup() {
render(h(comp), nodeOps.createElement('div'))
return () => null
},
}

createApp(App).mount(nodeOps.createElement('div'))
expect(
'Slot "default" invoked outside of the render function',
).toHaveBeenWarned()

Check failure on line 419 in packages/runtime-core/__tests__/componentSlots.spec.ts

View workflow job for this annotation

GitHub Actions / test / unit-test

packages/runtime-core/__tests__/componentSlots.spec.ts > component: slots > basic warn when render in setup

Error: expected "Slot "default" invoked outside of the render function" to have been warned but no warning was recorded. ❯ packages/runtime-core/__tests__/componentSlots.spec.ts:419:7
})
})

0 comments on commit e8e3cdf

Please sign in to comment.