|
8 | 8 | createStaticVNode |
9 | 9 | } from '@vue/runtime-dom' |
10 | 10 | import { renderToString } from '@vue/server-renderer' |
| 11 | +import { mockWarn } from '@vue/shared' |
11 | 12 |
|
12 | 13 | function mountWithHydration(html: string, render: () => any) { |
13 | 14 | const container = document.createElement('div') |
@@ -268,12 +269,48 @@ describe('SSR hydration', () => { |
268 | 269 | }) |
269 | 270 |
|
270 | 271 | describe('mismatch handling', () => { |
271 | | - test('text', () => {}) |
272 | | - |
273 | | - test('not enough children', () => {}) |
274 | | - |
275 | | - test('too many children', () => {}) |
276 | | - |
277 | | - test('complete mismatch', () => {}) |
| 272 | + mockWarn() |
| 273 | + |
| 274 | + test('text node', () => { |
| 275 | + const { container } = mountWithHydration(`foo`, () => 'bar') |
| 276 | + expect(container.textContent).toBe('bar') |
| 277 | + expect(`Hydration text mismatch`).toHaveBeenWarned() |
| 278 | + }) |
| 279 | + |
| 280 | + test('element text content', () => { |
| 281 | + const { container } = mountWithHydration(`<div>foo</div>`, () => |
| 282 | + h('div', 'bar') |
| 283 | + ) |
| 284 | + expect(container.innerHTML).toBe('<div>bar</div>') |
| 285 | + expect(`Hydration text content mismatch in <div>`).toHaveBeenWarned() |
| 286 | + }) |
| 287 | + |
| 288 | + test('not enough children', () => { |
| 289 | + const { container } = mountWithHydration(`<div></div>`, () => |
| 290 | + h('div', [h('span', 'foo'), h('span', 'bar')]) |
| 291 | + ) |
| 292 | + expect(container.innerHTML).toBe( |
| 293 | + '<div><span>foo</span><span>bar</span></div>' |
| 294 | + ) |
| 295 | + expect(`Hydration children mismatch in <div>`).toHaveBeenWarned() |
| 296 | + }) |
| 297 | + |
| 298 | + test('too many children', () => { |
| 299 | + const { container } = mountWithHydration( |
| 300 | + `<div><span>foo</span><span>bar</span></div>`, |
| 301 | + () => h('div', [h('span', 'foo')]) |
| 302 | + ) |
| 303 | + expect(container.innerHTML).toBe('<div><span>foo</span></div>') |
| 304 | + expect(`Hydration children mismatch in <div>`).toHaveBeenWarned() |
| 305 | + }) |
| 306 | + |
| 307 | + test('complete mismatch', () => { |
| 308 | + const { container } = mountWithHydration( |
| 309 | + `<div><span>foo</span><span>bar</span></div>`, |
| 310 | + () => h('div', [h('div', 'foo'), h('p', 'bar')]) |
| 311 | + ) |
| 312 | + expect(container.innerHTML).toBe('<div><div>foo</div><p>bar</p></div>') |
| 313 | + expect(`Hydration node mismatch`).toHaveBeenWarnedTimes(2) |
| 314 | + }) |
278 | 315 | }) |
279 | 316 | }) |
0 commit comments