type Ref,
TrackOpTypes,
TriggerOpTypes,
- createComponent,
- createIf,
- createTextNode,
- getCurrentInstance,
+ currentInstance,
inject,
nextTick,
onBeforeMount,
provide,
reactive,
ref,
+} from '@vue/runtime-dom'
+import {
+ createComponent,
+ // createIf,
+ createTextNode,
renderEffect,
setText,
template,
const define = makeRender<any>()
-describe.todo('api: lifecycle hooks', () => {
+describe('api: lifecycle hooks', () => {
it('onBeforeMount', () => {
const fn = vi.fn(() => {
expect(host.innerHTML).toBe(``)
const { render, host } = define({
setup() {
onBeforeMount(fn)
- return () => template('<div></div>')()
+ return []
},
})
render()
const { render, host } = define({
setup() {
onMounted(fn)
- return () => template('<div></div>')()
+ return []
},
})
render()
const { render, host } = define({
setup() {
onBeforeUpdate(fn)
- return (() => {
- const n0 = createTextNode()
- renderEffect(() => {
- setText(n0, count.value)
- })
- return n0
- })()
+ const n0 = createTextNode()
+ renderEffect(() => {
+ setText(n0, count.value)
+ })
+ return n0
},
})
render()
const { render, host } = define({
setup() {
onBeforeUpdate(fn)
- return (() => {
- const n0 = createTextNode()
- renderEffect(() => {
- renderSpy()
- setText(n0, count.value)
- })
- return n0
- })()
+ const n0 = createTextNode()
+ renderEffect(() => {
+ renderSpy()
+ setText(n0, count.value)
+ })
+ return n0
},
})
render()
const { render, host } = define({
setup() {
onUpdated(fn)
- return (() => {
- const n0 = createTextNode()
- renderEffect(() => {
- setText(n0, count.value)
- })
- return n0
- })()
+
+ const n0 = createTextNode()
+ renderEffect(() => {
+ setText(n0, count.value)
+ })
+ return n0
},
})
render()
expect(fn).toHaveBeenCalledTimes(1)
})
- it('onBeforeUnmount', async () => {
+ it.todo('onBeforeUnmount', async () => {
const toggle = ref(true)
const fn = vi.fn(() => {
expect(host.innerHTML).toBe('<div></div>')
})
const { render, host } = define({
setup() {
- return (() => {
- const n0 = createIf(
- () => toggle.value,
- () => createComponent(Child),
- )
- return n0
- })()
+ // @ts-expect-error
+ const n0 = createIf(
+ () => toggle.value,
+ () => createComponent(Child),
+ )
+ return n0
},
})
const Child = {
setup() {
onBeforeUnmount(fn)
- return (() => {
- const t0 = template('<div></div>')
- const n0 = t0()
- return n0
- })()
+
+ const t0 = template('<div></div>')
+ const n0 = t0()
+ return n0
},
}
expect(host.innerHTML).toBe('<!--if-->')
})
- it('onUnmounted', async () => {
+ it.todo('onUnmounted', async () => {
const toggle = ref(true)
const fn = vi.fn(() => {
expect(host.innerHTML).toBe('<div></div>')
})
const { render, host } = define({
setup() {
- return (() => {
- const n0 = createIf(
- () => toggle.value,
- () => createComponent(Child),
- )
- return n0
- })()
+ // @ts-expect-error
+ const n0 = createIf(
+ () => toggle.value,
+ () => createComponent(Child),
+ )
+ return n0
},
})
const Child = {
setup() {
onUnmounted(fn)
- return (() => {
- const t0 = template('<div></div>')
- const n0 = t0()
- return n0
- })()
+
+ const t0 = template('<div></div>')
+ const n0 = t0()
+ return n0
},
}
expect(host.innerHTML).toBe('<!--if-->')
})
- it('onBeforeUnmount in onMounted', async () => {
+ it.todo('onBeforeUnmount in onMounted', async () => {
const toggle = ref(true)
const fn = vi.fn(() => {
expect(host.innerHTML).toBe('<div></div>')
})
const { render, host } = define({
setup() {
- return (() => {
- const n0 = createIf(
- () => toggle.value,
- () => createComponent(Child),
- )
- return n0
- })()
+ // @ts-expect-error
+ const n0 = createIf(
+ () => toggle.value,
+ () => createComponent(Child),
+ )
+ return n0
},
})
onMounted(() => {
onBeforeUnmount(fn)
})
- return (() => {
- const t0 = template('<div></div>')
- const n0 = t0()
- return n0
- })()
+
+ const t0 = template('<div></div>')
+ const n0 = t0()
+ return n0
},
}
expect(host.innerHTML).toBe('<!--if-->')
})
- it('lifecycle call order', async () => {
+ it.todo('lifecycle call order', async () => {
const count = ref(0)
const toggle = ref(true)
const calls: string[] = []
onUpdated(() => calls.push('onUpdated'))
onBeforeUnmount(() => calls.push('onBeforeUnmount'))
onUnmounted(() => calls.push('onUnmounted'))
- return (() => {
- const n0 = createIf(
- () => toggle.value,
- () => createComponent(Mid, { count: () => count.value }),
- )
- return n0
- })()
+
+ // @ts-expect-error
+ const n0 = createIf(
+ () => toggle.value,
+ () => createComponent(Mid, { count: () => count.value }),
+ )
+ return n0
},
})
onUpdated(() => calls.push('mid onUpdated'))
onBeforeUnmount(() => calls.push('mid onBeforeUnmount'))
onUnmounted(() => calls.push('mid onUnmounted'))
- return (() => {
- const n0 = createComponent(Child, { count: () => props.count })
- return n0
- })()
+
+ const n0 = createComponent(Child, { count: () => props.count })
+ return n0
},
}
onUpdated(() => calls.push('child onUpdated'))
onBeforeUnmount(() => calls.push('child onBeforeUnmount'))
onUnmounted(() => calls.push('child onUnmounted'))
- return (() => {
- const t0 = template('<div></div>')
- const n0 = t0()
- renderEffect(() => setText(n0, props.count))
- return n0
- })()
+
+ const t0 = template('<div></div>')
+ const n0 = t0()
+ renderEffect(() => setText(n0, props.count))
+ return n0
},
}
const { render } = define({
setup() {
onRenderTracked(onTrack)
- return (() => {
- const n0 = createTextNode()
- renderEffect(() => {
- setText(n0, [obj.foo, 'bar' in obj, Object.keys(obj).join('')])
- })
- return n0
- })()
+
+ const n0 = createTextNode()
+ renderEffect(() => {
+ setText(n0, [obj.foo, 'bar' in obj, Object.keys(obj).join('')])
+ })
+ return n0
},
})
const { render } = define({
setup() {
onRenderTriggered(onTrigger)
- return (() => {
- const n0 = createTextNode()
- renderEffect(() => {
- setText(n0, [obj.foo, 'bar' in obj, Object.keys(obj).join('')])
- })
- return n0
- })()
+
+ const n0 = createTextNode()
+ renderEffect(() => {
+ setText(n0, [obj.foo, 'bar' in obj, Object.keys(obj).join('')])
+ })
+ return n0
},
})
})
})
- it('runs shared hook fn for each instance', async () => {
+ it.todo('runs shared hook fn for each instance', async () => {
const fn = vi.fn()
const toggle = ref(true)
const { render } = define({
setup() {
+ // @ts-expect-error
return createIf(
() => toggle.value,
() => [createComponent(Child), createComponent(Child)],
const { render, host } = define({
setup() {
onUpdated(() => handleUpdated())
- return (() => {
- const n0 = createTextNode()
- renderEffect(() => setText(n0, count.value))
- const n1 = createComponent(Child, { count: () => count.value })
- return [n0, n1]
- })()
+
+ const n0 = createTextNode()
+ renderEffect(() => setText(n0, count.value))
+ const n1 = createComponent(Child, { count: () => count.value })
+ return [n0, n1]
},
})
props: { count: Number },
setup() {
onUpdated(() => handleUpdatedChild())
- return (() => {
- const props = getCurrentInstance()!.props
- const n2 = createTextNode()
- renderEffect(() => setText(n2, props.count))
- return n2
- })()
+
+ const props = currentInstance!.props
+ const n2 = createTextNode()
+ renderEffect(() => setText(n2, props.count))
+ return n2
},
}
const count = ref(0)
provide(key, count)
onUpdated(() => handleUpdated())
- return (() => {
- const n0 = createTextNode()
- renderEffect(() => setText(n0, count.value))
- const n1 = createComponent(Child, { count: () => count.value })
- return [n0, n1]
- })()
+
+ const n0 = createTextNode()
+ renderEffect(() => setText(n0, count.value))
+ const n1 = createComponent(Child, { count: () => count.value })
+ return [n0, n1]
},
})
onUpdated(() => handleUpdatedChild())
const count = inject(key)!
update = () => count.value++
- return (() => {
- const n2 = createTextNode()
- renderEffect(() => setText(n2, count.value))
- return n2
- })()
+
+ const n2 = createTextNode()
+ renderEffect(() => setText(n2, count.value))
+ return n2
},
}