Skip to content

Commit

Permalink
test(runtime-vapor): fix type (#229)
Browse files Browse the repository at this point in the history
  • Loading branch information
Doctor-wu authored Jun 16, 2024
1 parent a1797f8 commit ad3d8fa
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 21 deletions.
13 changes: 3 additions & 10 deletions packages/runtime-vapor/__tests__/componentAttrs.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {
template,
watchEffect,
} from '../src'
import { setCurrentInstance } from '../src/component'
import { makeRender } from './_utils'

const define = makeRender<any>()
Expand All @@ -27,7 +26,7 @@ describe('attribute fallthrough', () => {

const foo = ref(1)
const id = ref('a')
const { instance, host } = define({
const { host } = define({
setup() {
return { foo, id }
},
Expand All @@ -46,7 +45,6 @@ describe('attribute fallthrough', () => {
)
},
}).render()
const reset = setCurrentInstance(instance)
expect(host.innerHTML).toBe('<div id="a">1</div>')

foo.value++
Expand All @@ -56,7 +54,6 @@ describe('attribute fallthrough', () => {
id.value = 'b'
await nextTick()
expect(host.innerHTML).toBe('<div id="b">2</div>')
reset()
})

it('should not fallthrough if explicitly pass inheritAttrs: false', async () => {
Expand All @@ -74,7 +71,7 @@ describe('attribute fallthrough', () => {

const foo = ref(1)
const id = ref('a')
const { instance, host } = define({
const { host } = define({
setup() {
return { foo, id }
},
Expand All @@ -93,7 +90,6 @@ describe('attribute fallthrough', () => {
)
},
}).render()
const reset = setCurrentInstance(instance)
expect(host.innerHTML).toBe('<div>1</div>')

foo.value++
Expand All @@ -103,7 +99,6 @@ describe('attribute fallthrough', () => {
id.value = 'b'
await nextTick()
expect(host.innerHTML).toBe('<div>2</div>')
reset()
})

it('should pass through attrs in nested single root components', async () => {
Expand Down Expand Up @@ -137,7 +132,7 @@ describe('attribute fallthrough', () => {

const foo = ref(1)
const id = ref('a')
const { instance, host } = define({
const { host } = define({
setup() {
return { foo, id }
},
Expand All @@ -156,7 +151,6 @@ describe('attribute fallthrough', () => {
)
},
}).render()
const reset = setCurrentInstance(instance)
expect(host.innerHTML).toBe('<div foo="1" id="a">1</div>')

foo.value++
Expand All @@ -166,6 +160,5 @@ describe('attribute fallthrough', () => {
id.value = 'b'
await nextTick()
expect(host.innerHTML).toBe('<div foo="2" id="b">2</div>')
reset()
})
})
2 changes: 1 addition & 1 deletion packages/runtime-vapor/__tests__/componentExpose.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ describe('component expose', () => {
},
})
const { instance } = render()
expect(instance.exposed).toEqual(expxosedObj)
expect(instance?.exposed).toEqual(expxosedObj)
})

test('should warn when called multiple times', async () => {
Expand Down
5 changes: 1 addition & 4 deletions packages/runtime-vapor/__tests__/componentProps.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// NOTE: This test is implemented based on the case of `runtime-core/__test__/componentProps.spec.ts`.

import { setCurrentInstance } from '../src/component'
import {
createComponent,
defineComponent,
Expand Down Expand Up @@ -233,7 +232,7 @@ describe('component: props', () => {

const foo = ref(1)
const id = ref('a')
const { instance, host } = define({
const { host } = define({
setup() {
return { foo, id }
},
Expand All @@ -250,7 +249,6 @@ describe('component: props', () => {
)
},
}).render()
const reset = setCurrentInstance(instance)
expect(host.innerHTML).toBe('<div id="a">1</div>')

foo.value++
Expand All @@ -260,7 +258,6 @@ describe('component: props', () => {
id.value = 'b'
await nextTick()
expect(host.innerHTML).toBe('<div id="b">2</div>')
reset()
})

describe('validator', () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/runtime-vapor/__tests__/directives/vShow.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ describe('directive: v-show', () => {
}).render()

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')
btn?.click()
Expand Down
2 changes: 1 addition & 1 deletion packages/runtime-vapor/__tests__/for.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ describe('createFor', () => {
calls.length = 0
expect(spySrcFn).toHaveBeenCalledTimes(7)

unmountComponent(instance)
unmountComponent(instance!)
expect(calls).toEqual(['0 beforeUnmount', '0 unmounted'])
expect(spySrcFn).toHaveBeenCalledTimes(7)
})
Expand Down
2 changes: 1 addition & 1 deletion packages/runtime-vapor/__tests__/if.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ describe('createIf', () => {
expect(spyConditionFn1).toHaveBeenCalledTimes(3)
expect(spyConditionFn2).toHaveBeenCalledTimes(2)

unmountComponent(instance)
unmountComponent(instance!)
expect(calls).toEqual(['1 beforeUnmount', '1 unmounted'])
expect(spyConditionFn1).toHaveBeenCalledTimes(3)
expect(spyConditionFn2).toHaveBeenCalledTimes(2)
Expand Down
6 changes: 3 additions & 3 deletions packages/runtime-vapor/__tests__/renderEffect.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ describe('renderEffect', () => {
})
},
).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'])
calls.length = 0
Expand Down Expand Up @@ -173,7 +173,7 @@ describe('renderEffect', () => {
})
},
).render()
const { update } = instance.setupState as any
const { update } = instance?.setupState as any
await expect(async () => {
update()
await nextTick()
Expand Down Expand Up @@ -203,7 +203,7 @@ describe('renderEffect', () => {
},
).render()

const { update } = instance.setupState as any
const { update } = instance?.setupState as any
await expect(async () => {
update()
await nextTick()
Expand Down

0 comments on commit ad3d8fa

Please sign in to comment.