Skip to content

Commit a37e2c5

Browse files
committed
wip: save
1 parent ae5d0a4 commit a37e2c5

File tree

1 file changed

+48
-32
lines changed

1 file changed

+48
-32
lines changed

packages/runtime-vapor/__tests__/hmr.spec.ts

Lines changed: 48 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,16 @@
1-
import { type HMRRuntime, nextTick, ref } from '@vue/runtime-dom'
1+
import {
2+
type HMRRuntime,
3+
nextTick,
4+
onMounted,
5+
onUnmounted,
6+
ref,
7+
} from '@vue/runtime-dom'
28
import { compileToVaporRender as compileToFunction, makeRender } from './_utils'
3-
import { defineVaporComponent, delegateEvents } from '@vue/runtime-vapor'
9+
import {
10+
createComponent,
11+
defineVaporComponent,
12+
delegateEvents,
13+
} from '@vue/runtime-vapor'
414

515
declare var __VUE_HMR_RUNTIME__: HMRRuntime
616
const { createRecord, rerender, reload } = __VUE_HMR_RUNTIME__
@@ -113,36 +123,42 @@ describe('hot module replacement', () => {
113123
})
114124

115125
test('reload', async () => {
116-
// const root = nodeOps.createElement('div')
117-
// const childId = 'test3-child'
118-
// const unmountSpy = vi.fn()
119-
// const mountSpy = vi.fn()
120-
// const Child: ComponentOptions = {
121-
// __hmrId: childId,
122-
// data() {
123-
// return { count: 0 }
124-
// },
125-
// unmounted: unmountSpy,
126-
// render: compileToFunction(`<div @click="count++">{{ count }}</div>`),
127-
// }
128-
// createRecord(childId, Child)
129-
// const Parent: ComponentOptions = {
130-
// render: () => h(Child),
131-
// }
132-
// render(h(Parent), root)
133-
// expect(serializeInner(root)).toBe(`<div>0</div>`)
134-
// reload(childId, {
135-
// __hmrId: childId,
136-
// data() {
137-
// return { count: 1 }
138-
// },
139-
// mounted: mountSpy,
140-
// render: compileToFunction(`<div @click="count++">{{ count }}</div>`),
141-
// })
142-
// await nextTick()
143-
// expect(serializeInner(root)).toBe(`<div>1</div>`)
144-
// expect(unmountSpy).toHaveBeenCalledTimes(1)
145-
// expect(mountSpy).toHaveBeenCalledTimes(1)
126+
const root = document.createElement('div')
127+
const childId = 'test3-child'
128+
const unmountSpy = vi.fn()
129+
const mountSpy = vi.fn()
130+
const Child = defineVaporComponent({
131+
__hmrId: childId,
132+
setup() {
133+
onUnmounted(unmountSpy)
134+
const count = ref(0)
135+
return { count }
136+
},
137+
render: compileToFunction(`<div @click="count++">{{ count }}</div>`),
138+
})
139+
createRecord(childId, Child as any)
140+
141+
const Parent = defineVaporComponent({
142+
__hmrId: 'parentId',
143+
render: () => createComponent(Child),
144+
})
145+
146+
define(Parent).create().mount(root)
147+
expect(root.innerHTML).toBe(`<div>0</div>`)
148+
149+
reload(childId, {
150+
__hmrId: childId,
151+
setup() {
152+
onMounted(mountSpy)
153+
const count = ref(1)
154+
return { count }
155+
},
156+
render: compileToFunction(`<div @click="count++">{{ count }}</div>`),
157+
})
158+
await nextTick()
159+
expect(root.innerHTML).toBe(`<div>1</div>`)
160+
expect(unmountSpy).toHaveBeenCalledTimes(1)
161+
expect(mountSpy).toHaveBeenCalledTimes(1)
146162
})
147163

148164
test('child reload + parent reload', async () => {

0 commit comments

Comments
 (0)