Skip to content

Commit

Permalink
test: add test case
Browse files Browse the repository at this point in the history
  • Loading branch information
edison1105 committed Oct 25, 2024
1 parent 2ea0046 commit 52b0b73
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions packages/runtime-core/__tests__/hmr.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
import * as runtimeTest from '@vue/runtime-test'
import { createApp, registerRuntimeCompiler } from '@vue/runtime-test'
import { baseCompile } from '@vue/compiler-core'
import { createSSRApp } from '@vue/runtime-dom'

declare var __VUE_HMR_RUNTIME__: HMRRuntime
const { createRecord, rerender, reload } = __VUE_HMR_RUNTIME__
Expand Down Expand Up @@ -894,4 +895,41 @@ describe('hot module replacement', () => {
await timeout()
expect(serializeInner(root)).toBe('<div>bar</div>')
})

/**
* @vitest-environment jsdom
*/
test('reload child wrapped in KeepAlive', async () => {
const id = 'child-reload'
const Child: ComponentOptions = {
__hmrId: id,
render: compileToFunction(`<div>foo</div>`),
}
createRecord(id, Child)

const appId = 'test-app-id'
const App: ComponentOptions = {
__hmrId: appId,
components: { Child },
render: compileToFunction(`
<div>
<KeepAlive>
<Child />
</KeepAlive>
</div>
`),
}

const root = document.createElement('div')
root.innerHTML = runtimeTest.renderToString(h(App))
createSSRApp(App).mount(root)
expect(root.innerHTML).toBe('<div><div>foo</div></div>')

reload(id, {
__hmrId: id,
render: compileToFunction(`<div>bar</div>`),
})
await timeout()
expect(root.innerHTML).toBe('<div><div>bar</div></div>')
})
})

0 comments on commit 52b0b73

Please sign in to comment.