test(runtime-vapor): fix type (#229)

This commit is contained in:
Doctor Wu 2024-06-16 16:50:24 +08:00 committed by GitHub
parent a1797f8861
commit ad3d8fa6b4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 11 additions and 21 deletions

View File

@ -7,7 +7,6 @@ import {
template, template,
watchEffect, watchEffect,
} from '../src' } from '../src'
import { setCurrentInstance } from '../src/component'
import { makeRender } from './_utils' import { makeRender } from './_utils'
const define = makeRender<any>() const define = makeRender<any>()
@ -27,7 +26,7 @@ describe('attribute fallthrough', () => {
const foo = ref(1) const foo = ref(1)
const id = ref('a') const id = ref('a')
const { instance, host } = define({ const { host } = define({
setup() { setup() {
return { foo, id } return { foo, id }
}, },
@ -46,7 +45,6 @@ describe('attribute fallthrough', () => {
) )
}, },
}).render() }).render()
const reset = setCurrentInstance(instance)
expect(host.innerHTML).toBe('<div id="a">1</div>') expect(host.innerHTML).toBe('<div id="a">1</div>')
foo.value++ foo.value++
@ -56,7 +54,6 @@ describe('attribute fallthrough', () => {
id.value = 'b' id.value = 'b'
await nextTick() await nextTick()
expect(host.innerHTML).toBe('<div id="b">2</div>') expect(host.innerHTML).toBe('<div id="b">2</div>')
reset()
}) })
it('should not fallthrough if explicitly pass inheritAttrs: false', async () => { it('should not fallthrough if explicitly pass inheritAttrs: false', async () => {
@ -74,7 +71,7 @@ describe('attribute fallthrough', () => {
const foo = ref(1) const foo = ref(1)
const id = ref('a') const id = ref('a')
const { instance, host } = define({ const { host } = define({
setup() { setup() {
return { foo, id } return { foo, id }
}, },
@ -93,7 +90,6 @@ describe('attribute fallthrough', () => {
) )
}, },
}).render() }).render()
const reset = setCurrentInstance(instance)
expect(host.innerHTML).toBe('<div>1</div>') expect(host.innerHTML).toBe('<div>1</div>')
foo.value++ foo.value++
@ -103,7 +99,6 @@ describe('attribute fallthrough', () => {
id.value = 'b' id.value = 'b'
await nextTick() await nextTick()
expect(host.innerHTML).toBe('<div>2</div>') expect(host.innerHTML).toBe('<div>2</div>')
reset()
}) })
it('should pass through attrs in nested single root components', async () => { it('should pass through attrs in nested single root components', async () => {
@ -137,7 +132,7 @@ describe('attribute fallthrough', () => {
const foo = ref(1) const foo = ref(1)
const id = ref('a') const id = ref('a')
const { instance, host } = define({ const { host } = define({
setup() { setup() {
return { foo, id } return { foo, id }
}, },
@ -156,7 +151,6 @@ describe('attribute fallthrough', () => {
) )
}, },
}).render() }).render()
const reset = setCurrentInstance(instance)
expect(host.innerHTML).toBe('<div foo="1" id="a">1</div>') expect(host.innerHTML).toBe('<div foo="1" id="a">1</div>')
foo.value++ foo.value++
@ -166,6 +160,5 @@ describe('attribute fallthrough', () => {
id.value = 'b' id.value = 'b'
await nextTick() await nextTick()
expect(host.innerHTML).toBe('<div foo="2" id="b">2</div>') expect(host.innerHTML).toBe('<div foo="2" id="b">2</div>')
reset()
}) })
}) })

View File

@ -13,7 +13,7 @@ describe('component expose', () => {
}, },
}) })
const { instance } = render() const { instance } = render()
expect(instance.exposed).toEqual(expxosedObj) expect(instance?.exposed).toEqual(expxosedObj)
}) })
test('should warn when called multiple times', async () => { test('should warn when called multiple times', async () => {

View File

@ -1,6 +1,5 @@
// NOTE: This test is implemented based on the case of `runtime-core/__test__/componentProps.spec.ts`. // NOTE: This test is implemented based on the case of `runtime-core/__test__/componentProps.spec.ts`.
import { setCurrentInstance } from '../src/component'
import { import {
createComponent, createComponent,
defineComponent, defineComponent,
@ -233,7 +232,7 @@ describe('component: props', () => {
const foo = ref(1) const foo = ref(1)
const id = ref('a') const id = ref('a')
const { instance, host } = define({ const { host } = define({
setup() { setup() {
return { foo, id } return { foo, id }
}, },
@ -250,7 +249,6 @@ describe('component: props', () => {
) )
}, },
}).render() }).render()
const reset = setCurrentInstance(instance)
expect(host.innerHTML).toBe('<div id="a">1</div>') expect(host.innerHTML).toBe('<div id="a">1</div>')
foo.value++ foo.value++
@ -260,7 +258,6 @@ describe('component: props', () => {
id.value = 'b' id.value = 'b'
await nextTick() await nextTick()
expect(host.innerHTML).toBe('<div id="b">2</div>') expect(host.innerHTML).toBe('<div id="b">2</div>')
reset()
}) })
describe('validator', () => { describe('validator', () => {

View File

@ -77,7 +77,7 @@ describe('directive: v-show', () => {
}).render() }).render()
expect(host.innerHTML).toBe('<button>toggle</button><div>child</div>') expect(host.innerHTML).toBe('<button>toggle</button><div>child</div>')
expect(instance.scope.dirs!.get(n0)![0].dir).toBe(vShow) expect(instance?.scope.dirs!.get(n0)![0].dir).toBe(vShow)
const btn = host.querySelector('button') const btn = host.querySelector('button')
btn?.click() btn?.click()

View File

@ -305,7 +305,7 @@ describe('createFor', () => {
calls.length = 0 calls.length = 0
expect(spySrcFn).toHaveBeenCalledTimes(7) expect(spySrcFn).toHaveBeenCalledTimes(7)
unmountComponent(instance) unmountComponent(instance!)
expect(calls).toEqual(['0 beforeUnmount', '0 unmounted']) expect(calls).toEqual(['0 beforeUnmount', '0 unmounted'])
expect(spySrcFn).toHaveBeenCalledTimes(7) expect(spySrcFn).toHaveBeenCalledTimes(7)
}) })

View File

@ -237,7 +237,7 @@ describe('createIf', () => {
expect(spyConditionFn1).toHaveBeenCalledTimes(3) expect(spyConditionFn1).toHaveBeenCalledTimes(3)
expect(spyConditionFn2).toHaveBeenCalledTimes(2) expect(spyConditionFn2).toHaveBeenCalledTimes(2)
unmountComponent(instance) unmountComponent(instance!)
expect(calls).toEqual(['1 beforeUnmount', '1 unmounted']) expect(calls).toEqual(['1 beforeUnmount', '1 unmounted'])
expect(spyConditionFn1).toHaveBeenCalledTimes(3) expect(spyConditionFn1).toHaveBeenCalledTimes(3)
expect(spyConditionFn2).toHaveBeenCalledTimes(2) expect(spyConditionFn2).toHaveBeenCalledTimes(2)

View File

@ -110,7 +110,7 @@ describe('renderEffect', () => {
}) })
}, },
).render() ).render()
const { change, changeRender } = instance.setupState as any const { change, changeRender } = instance?.setupState as any
expect(calls).toEqual(['pre 0', 'sync 0', 'renderEffect 0', 'post 0']) expect(calls).toEqual(['pre 0', 'sync 0', 'renderEffect 0', 'post 0'])
calls.length = 0 calls.length = 0
@ -173,7 +173,7 @@ describe('renderEffect', () => {
}) })
}, },
).render() ).render()
const { update } = instance.setupState as any const { update } = instance?.setupState as any
await expect(async () => { await expect(async () => {
update() update()
await nextTick() await nextTick()
@ -203,7 +203,7 @@ describe('renderEffect', () => {
}, },
).render() ).render()
const { update } = instance.setupState as any const { update } = instance?.setupState as any
await expect(async () => { await expect(async () => {
update() update()
await nextTick() await nextTick()