From: daiwei Date: Fri, 31 Jan 2025 14:33:16 +0000 (+0800) Subject: test: add more tests X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=12df7309f4caffe787d0f32d9210ed15856d6e5a;p=thirdparty%2Fvuejs%2Fcore.git test: add more tests --- diff --git a/packages/runtime-core/__tests__/hydration.spec.ts b/packages/runtime-core/__tests__/hydration.spec.ts index 56011d0635..0a3e84b86c 100644 --- a/packages/runtime-core/__tests__/hydration.spec.ts +++ b/packages/runtime-core/__tests__/hydration.spec.ts @@ -2337,4 +2337,166 @@ describe('SSR hydration', () => { expect(`Hydration attribute mismatch`).not.toHaveBeenWarned() }) }) + + describe('v-skip', () => { + test('on native element', async () => { + const App = { + setup() { + const toggle = ref(true) + return { toggle } + }, + template: ` + +
foo
+ `, + } + const container = document.createElement('div') + // server render + container.innerHTML = await renderToString(h(App)) + // hydrate + createSSRApp(App).mount(container) + expect(container.innerHTML).toBe( + 'foo', + ) + + triggerEvent('click', container.querySelector('#toggleBtn')!) + await nextTick() + expect(container.innerHTML).toBe( + '
foo
', + ) + }) + + test('on component with default slot', async () => { + const Child = { + template: `
`, + } + const App = { + components: { Child }, + setup() { + const toggle = ref(true) + return { toggle } + }, + template: ` + + foo + `, + } + const container = document.createElement('div') + // server render + container.innerHTML = await renderToString(h(App)) + // hydrate + createSSRApp(App).mount(container) + expect(container.innerHTML).toBe( + 'foo', + ) + + triggerEvent('click', container.querySelector('#toggleBtn')!) + await nextTick() + expect(container.innerHTML).toBe( + '
foo
', + ) + }) + + test('on component with default slot + v-if', async () => { + const Child = { + template: `
`, + } + const App = { + components: { Child }, + setup() { + const toggle = ref(true) + return { toggle } + }, + template: ` + + foo + `, + } + const container = document.createElement('div') + // server render + container.innerHTML = await renderToString(h(App)) + // hydrate + createSSRApp(App).mount(container) + expect(container.innerHTML).toBe( + 'foo', + ) + + triggerEvent('click', container.querySelector('#toggleBtn')!) + await nextTick() + expect(container.innerHTML).toBe( + '
foo
', + ) + }) + + test('on component with dynamic slot', async () => { + const Child = { + template: `
`, + } + const App = { + components: { Child }, + setup() { + const toggle = ref(true) + const slotName = ref('default') + return { toggle, slotName } + }, + template: ` + + + + + `, + } + const container = document.createElement('div') + // server render + container.innerHTML = await renderToString(h(App)) + // hydrate + createSSRApp(App).mount(container) + expect(container.innerHTML).toBe( + 'foo', + ) + + triggerEvent('click', container.querySelector('#toggleBtn')!) + await nextTick() + expect(container.innerHTML).toBe( + '
foo
', + ) + }) + + test('on dynamic component with dynamic slot', async () => { + const Child = { + template: `
`, + } + const App = { + setup() { + const toggle = ref(true) + const slotName = ref('default') + return { toggle, slotName, Child } + }, + template: ` + + + + + `, + } + const container = document.createElement('div') + // server render + container.innerHTML = await renderToString(h(App)) + // hydrate + createSSRApp(App).mount(container) + expect(container.innerHTML).toBe( + 'foo', + ) + + triggerEvent('click', container.querySelector('#toggleBtn')!) + await nextTick() + expect(container.innerHTML).toBe( + '
foo
', + ) + }) + }) })