|
@@ -2,6 +2,7 @@ import {
|
|
|
type Ref,
|
|
type Ref,
|
|
|
inject,
|
|
inject,
|
|
|
nextTick,
|
|
nextTick,
|
|
|
|
|
+ onMounted,
|
|
|
onUpdated,
|
|
onUpdated,
|
|
|
provide,
|
|
provide,
|
|
|
ref,
|
|
ref,
|
|
@@ -13,6 +14,7 @@ import {
|
|
|
createIf,
|
|
createIf,
|
|
|
createTextNode,
|
|
createTextNode,
|
|
|
renderEffect,
|
|
renderEffect,
|
|
|
|
|
+ setInsertionState,
|
|
|
template,
|
|
template,
|
|
|
} from '../src'
|
|
} from '../src'
|
|
|
import { makeRender } from './_utils'
|
|
import { makeRender } from './_utils'
|
|
@@ -266,6 +268,29 @@ describe('component', () => {
|
|
|
expect(spy).toHaveBeenCalledTimes(2)
|
|
expect(spy).toHaveBeenCalledTimes(2)
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
|
|
+ it('properly mount child component when using setInsertionState', async () => {
|
|
|
|
|
+ const spy = vi.fn()
|
|
|
|
|
+
|
|
|
|
|
+ const { component: Comp } = define({
|
|
|
|
|
+ setup() {
|
|
|
|
|
+ onMounted(spy)
|
|
|
|
|
+ return template('<h1>hi</h1>')()
|
|
|
|
|
+ },
|
|
|
|
|
+ })
|
|
|
|
|
+
|
|
|
|
|
+ const { host } = define({
|
|
|
|
|
+ setup() {
|
|
|
|
|
+ const n2 = template('<div></div>', true)()
|
|
|
|
|
+ setInsertionState(n2 as any)
|
|
|
|
|
+ createComponent(Comp)
|
|
|
|
|
+ return n2
|
|
|
|
|
+ },
|
|
|
|
|
+ }).render()
|
|
|
|
|
+
|
|
|
|
|
+ expect(host.innerHTML).toBe('<div><h1>hi</h1></div>')
|
|
|
|
|
+ expect(spy).toHaveBeenCalledTimes(1)
|
|
|
|
|
+ })
|
|
|
|
|
+
|
|
|
it('unmount component', async () => {
|
|
it('unmount component', async () => {
|
|
|
const { host, app, instance } = define(() => {
|
|
const { host, app, instance } = define(() => {
|
|
|
const count = ref(0)
|
|
const count = ref(0)
|