mirror of https://github.com/vuejs/core.git
test: update test cases (#12678)
This commit is contained in:
parent
7b222990ae
commit
733d6fc13d
|
@ -21,7 +21,7 @@ import {
|
||||||
} from '@vue/runtime-dom'
|
} from '@vue/runtime-dom'
|
||||||
import {
|
import {
|
||||||
createComponent,
|
createComponent,
|
||||||
// createIf,
|
createIf,
|
||||||
createTextNode,
|
createTextNode,
|
||||||
renderEffect,
|
renderEffect,
|
||||||
setText,
|
setText,
|
||||||
|
@ -130,14 +130,13 @@ describe('api: lifecycle hooks', () => {
|
||||||
expect(fn).toHaveBeenCalledTimes(1)
|
expect(fn).toHaveBeenCalledTimes(1)
|
||||||
})
|
})
|
||||||
|
|
||||||
it.todo('onBeforeUnmount', async () => {
|
it('onBeforeUnmount', async () => {
|
||||||
const toggle = ref(true)
|
const toggle = ref(true)
|
||||||
const fn = vi.fn(() => {
|
const fn = vi.fn(() => {
|
||||||
expect(host.innerHTML).toBe('<div></div>')
|
expect(host.innerHTML).toBe('<div></div><!--if-->')
|
||||||
})
|
})
|
||||||
const { render, host } = define({
|
const { render, host } = define({
|
||||||
setup() {
|
setup() {
|
||||||
// @ts-expect-error
|
|
||||||
const n0 = createIf(
|
const n0 = createIf(
|
||||||
() => toggle.value,
|
() => toggle.value,
|
||||||
() => createComponent(Child),
|
() => createComponent(Child),
|
||||||
|
@ -160,18 +159,17 @@ describe('api: lifecycle hooks', () => {
|
||||||
|
|
||||||
toggle.value = false
|
toggle.value = false
|
||||||
await nextTick()
|
await nextTick()
|
||||||
// expect(fn).toHaveBeenCalledTimes(1) // FIXME: not called
|
expect(fn).toHaveBeenCalledTimes(1)
|
||||||
expect(host.innerHTML).toBe('<!--if-->')
|
expect(host.innerHTML).toBe('<!--if-->')
|
||||||
})
|
})
|
||||||
|
|
||||||
it.todo('onUnmounted', async () => {
|
it('onUnmounted', async () => {
|
||||||
const toggle = ref(true)
|
const toggle = ref(true)
|
||||||
const fn = vi.fn(() => {
|
const fn = vi.fn(() => {
|
||||||
expect(host.innerHTML).toBe('<div></div>')
|
expect(host.innerHTML).toBe('<!--if-->')
|
||||||
})
|
})
|
||||||
const { render, host } = define({
|
const { render, host } = define({
|
||||||
setup() {
|
setup() {
|
||||||
// @ts-expect-error
|
|
||||||
const n0 = createIf(
|
const n0 = createIf(
|
||||||
() => toggle.value,
|
() => toggle.value,
|
||||||
() => createComponent(Child),
|
() => createComponent(Child),
|
||||||
|
@ -194,18 +192,17 @@ describe('api: lifecycle hooks', () => {
|
||||||
|
|
||||||
toggle.value = false
|
toggle.value = false
|
||||||
await nextTick()
|
await nextTick()
|
||||||
// expect(fn).toHaveBeenCalledTimes(1) // FIXME: not called
|
expect(fn).toHaveBeenCalledTimes(1)
|
||||||
expect(host.innerHTML).toBe('<!--if-->')
|
expect(host.innerHTML).toBe('<!--if-->')
|
||||||
})
|
})
|
||||||
|
|
||||||
it.todo('onBeforeUnmount in onMounted', async () => {
|
it('onBeforeUnmount in onMounted', async () => {
|
||||||
const toggle = ref(true)
|
const toggle = ref(true)
|
||||||
const fn = vi.fn(() => {
|
const fn = vi.fn(() => {
|
||||||
expect(host.innerHTML).toBe('<div></div>')
|
expect(host.innerHTML).toBe('<div></div><!--if-->')
|
||||||
})
|
})
|
||||||
const { render, host } = define({
|
const { render, host } = define({
|
||||||
setup() {
|
setup() {
|
||||||
// @ts-expect-error
|
|
||||||
const n0 = createIf(
|
const n0 = createIf(
|
||||||
() => toggle.value,
|
() => toggle.value,
|
||||||
() => createComponent(Child),
|
() => createComponent(Child),
|
||||||
|
@ -230,25 +227,24 @@ describe('api: lifecycle hooks', () => {
|
||||||
|
|
||||||
toggle.value = false
|
toggle.value = false
|
||||||
await nextTick()
|
await nextTick()
|
||||||
// expect(fn).toHaveBeenCalledTimes(1) // FIXME: not called
|
expect(fn).toHaveBeenCalledTimes(1)
|
||||||
expect(host.innerHTML).toBe('<!--if-->')
|
expect(host.innerHTML).toBe('<!--if-->')
|
||||||
})
|
})
|
||||||
|
|
||||||
it.todo('lifecycle call order', async () => {
|
it('lifecycle call order', async () => {
|
||||||
const count = ref(0)
|
const count = ref(0)
|
||||||
const toggle = ref(true)
|
const toggle = ref(true)
|
||||||
const calls: string[] = []
|
const calls: string[] = []
|
||||||
|
|
||||||
const { render } = define({
|
const { render } = define({
|
||||||
setup() {
|
setup() {
|
||||||
onBeforeMount(() => calls.push('onBeforeMount'))
|
onBeforeMount(() => calls.push('root onBeforeMount'))
|
||||||
onMounted(() => calls.push('onMounted'))
|
onMounted(() => calls.push('root onMounted'))
|
||||||
onBeforeUpdate(() => calls.push('onBeforeUpdate'))
|
onBeforeUpdate(() => calls.push('root onBeforeUpdate'))
|
||||||
onUpdated(() => calls.push('onUpdated'))
|
onUpdated(() => calls.push('root onUpdated'))
|
||||||
onBeforeUnmount(() => calls.push('onBeforeUnmount'))
|
onBeforeUnmount(() => calls.push('root onBeforeUnmount'))
|
||||||
onUnmounted(() => calls.push('onUnmounted'))
|
onUnmounted(() => calls.push('root onUnmounted'))
|
||||||
|
|
||||||
// @ts-expect-error
|
|
||||||
const n0 = createIf(
|
const n0 = createIf(
|
||||||
() => toggle.value,
|
() => toggle.value,
|
||||||
() => createComponent(Mid, { count: () => count.value }),
|
() => createComponent(Mid, { count: () => count.value }),
|
||||||
|
@ -290,14 +286,14 @@ describe('api: lifecycle hooks', () => {
|
||||||
}
|
}
|
||||||
|
|
||||||
// mount
|
// mount
|
||||||
render()
|
const ctx = render()
|
||||||
expect(calls).toEqual([
|
expect(calls).toEqual([
|
||||||
'onBeforeMount',
|
'root onBeforeMount',
|
||||||
'mid onBeforeMount',
|
'mid onBeforeMount',
|
||||||
'child onBeforeMount',
|
'child onBeforeMount',
|
||||||
'child onMounted',
|
'child onMounted',
|
||||||
'mid onMounted',
|
'mid onMounted',
|
||||||
'onMounted',
|
'root onMounted',
|
||||||
])
|
])
|
||||||
|
|
||||||
calls.length = 0
|
calls.length = 0
|
||||||
|
@ -305,29 +301,22 @@ describe('api: lifecycle hooks', () => {
|
||||||
// update
|
// update
|
||||||
count.value++
|
count.value++
|
||||||
await nextTick()
|
await nextTick()
|
||||||
// FIXME: not called
|
// only child updated
|
||||||
// expect(calls).toEqual([
|
expect(calls).toEqual(['child onBeforeUpdate', 'child onUpdated'])
|
||||||
// 'root onBeforeUpdate',
|
|
||||||
// 'mid onBeforeUpdate',
|
|
||||||
// 'child onBeforeUpdate',
|
|
||||||
// 'child onUpdated',
|
|
||||||
// 'mid onUpdated',
|
|
||||||
// 'root onUpdated',
|
|
||||||
// ])
|
|
||||||
|
|
||||||
calls.length = 0
|
calls.length = 0
|
||||||
|
|
||||||
// unmount
|
// unmount
|
||||||
toggle.value = false
|
ctx.app.unmount()
|
||||||
// FIXME: not called
|
await nextTick()
|
||||||
// expect(calls).toEqual([
|
expect(calls).toEqual([
|
||||||
// 'root onBeforeUnmount',
|
'root onBeforeUnmount',
|
||||||
// 'mid onBeforeUnmount',
|
'mid onBeforeUnmount',
|
||||||
// 'child onBeforeUnmount',
|
'child onBeforeUnmount',
|
||||||
// 'child onUnmounted',
|
'child onUnmounted',
|
||||||
// 'mid onUnmounted',
|
'mid onUnmounted',
|
||||||
// 'root onUnmounted',
|
'root onUnmounted',
|
||||||
// ])
|
])
|
||||||
})
|
})
|
||||||
|
|
||||||
it('onRenderTracked', async () => {
|
it('onRenderTracked', async () => {
|
||||||
|
@ -422,12 +411,11 @@ describe('api: lifecycle hooks', () => {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
it.todo('runs shared hook fn for each instance', async () => {
|
it('runs shared hook fn for each instance', async () => {
|
||||||
const fn = vi.fn()
|
const fn = vi.fn()
|
||||||
const toggle = ref(true)
|
const toggle = ref(true)
|
||||||
const { render } = define({
|
const { render } = define({
|
||||||
setup() {
|
setup() {
|
||||||
// @ts-expect-error
|
|
||||||
return createIf(
|
return createIf(
|
||||||
() => toggle.value,
|
() => toggle.value,
|
||||||
() => [createComponent(Child), createComponent(Child)],
|
() => [createComponent(Child), createComponent(Child)],
|
||||||
|
@ -446,7 +434,7 @@ describe('api: lifecycle hooks', () => {
|
||||||
expect(fn).toHaveBeenCalledTimes(2)
|
expect(fn).toHaveBeenCalledTimes(2)
|
||||||
toggle.value = false
|
toggle.value = false
|
||||||
await nextTick()
|
await nextTick()
|
||||||
// expect(fn).toHaveBeenCalledTimes(4) // FIXME: not called unmounted hook
|
expect(fn).toHaveBeenCalledTimes(4)
|
||||||
})
|
})
|
||||||
|
|
||||||
// #136
|
// #136
|
||||||
|
|
|
@ -76,7 +76,7 @@ describe('api: template ref', () => {
|
||||||
expect(fooEl.value).toBe(null)
|
expect(fooEl.value).toBe(null)
|
||||||
})
|
})
|
||||||
|
|
||||||
it.todo('string ref unmount', async () => {
|
it('string ref unmount', async () => {
|
||||||
const t0 = template('<div></div>')
|
const t0 = template('<div></div>')
|
||||||
const el = ref(null)
|
const el = ref(null)
|
||||||
const toggle = ref(true)
|
const toggle = ref(true)
|
||||||
|
@ -153,7 +153,7 @@ describe('api: template ref', () => {
|
||||||
expect(fn2.mock.calls[0][0]).toBe(host.children[0])
|
expect(fn2.mock.calls[0][0]).toBe(host.children[0])
|
||||||
})
|
})
|
||||||
|
|
||||||
it.todo('function ref unmount', async () => {
|
it('function ref unmount', async () => {
|
||||||
const fn = vi.fn()
|
const fn = vi.fn()
|
||||||
const toggle = ref(true)
|
const toggle = ref(true)
|
||||||
|
|
||||||
|
@ -361,7 +361,7 @@ describe('api: template ref', () => {
|
||||||
})
|
})
|
||||||
|
|
||||||
// #1789
|
// #1789
|
||||||
test.todo('toggle the same ref to different elements', async () => {
|
test('toggle the same ref to different elements', async () => {
|
||||||
const refToggle = ref(false)
|
const refToggle = ref(false)
|
||||||
const spy = vi.fn()
|
const spy = vi.fn()
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue