Skip to content

Commit 474cb7f

Browse files
committed
wip: add tests for class mismatch
1 parent ab2c308 commit 474cb7f

File tree

1 file changed

+47
-23
lines changed

1 file changed

+47
-23
lines changed

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

Lines changed: 47 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3115,29 +3115,53 @@ describe('Vapor Mode hydration', () => {
31153115
// expect(container.innerHTML).toBe('<div><!--hi--></div>')
31163116
// expect(`Hydration node mismatch`).toHaveBeenWarned()
31173117
// })
3118-
test('class mismatch', () => {
3119-
// mountWithHydration(`<div class="foo bar"></div>`, () =>
3120-
// h('div', { class: ['foo', 'bar'] }),
3121-
// )
3122-
// mountWithHydration(`<div class="foo bar"></div>`, () =>
3123-
// h('div', { class: { foo: true, bar: true } }),
3124-
// )
3125-
// mountWithHydration(`<div class="foo bar"></div>`, () =>
3126-
// h('div', { class: 'foo bar' }),
3127-
// )
3128-
// // SVG classes
3129-
// mountWithHydration(`<svg class="foo bar"></svg>`, () =>
3130-
// h('svg', { class: 'foo bar' }),
3131-
// )
3132-
// // class with different order
3133-
// mountWithHydration(`<div class="foo bar"></div>`, () =>
3134-
// h('div', { class: 'bar foo' }),
3135-
// )
3136-
// expect(`Hydration class mismatch`).not.toHaveBeenWarned()
3137-
// mountWithHydration(`<div class="foo bar"></div>`, () =>
3138-
// h('div', { class: 'foo' }),
3139-
// )
3140-
// expect(`Hydration class mismatch`).toHaveBeenWarned()
3118+
test('class mismatch', async () => {
3119+
await mountWithHydration(
3120+
`<div class="foo bar"></div>`,
3121+
`<div :class="data"></div>`,
3122+
ref(['foo', 'bar']),
3123+
)
3124+
await mountWithHydration(
3125+
`<div class="foo bar"></div>`,
3126+
`<div :class="data"></div>`,
3127+
ref({ foo: true, bar: true }),
3128+
)
3129+
await mountWithHydration(
3130+
`<div class="foo bar"></div>`,
3131+
`<div :class="data"></div>`,
3132+
ref('foo bar'),
3133+
)
3134+
// svg classes
3135+
await mountWithHydration(
3136+
`<svg class="foo bar"></svg>`,
3137+
`<svg :class="data"></svg>`,
3138+
ref('foo bar'),
3139+
)
3140+
// class with different order
3141+
await mountWithHydration(
3142+
`<div class="foo bar"></div>`,
3143+
`<div :class="data"></div>`,
3144+
ref('bar foo'),
3145+
)
3146+
expect(`Hydration class mismatch`).not.toHaveBeenWarned()
3147+
3148+
// single root mismatch
3149+
const { container: root } = await mountWithHydration(
3150+
`<div class="foo bar"></div>`,
3151+
`<div :class="data"></div>`,
3152+
ref('baz'),
3153+
)
3154+
expect(root.innerHTML).toBe('<div class="foo bar baz"></div>')
3155+
expect(`Hydration class mismatch`).toHaveBeenWarned()
3156+
3157+
// multiple root mismatch
3158+
const { container } = await mountWithHydration(
3159+
`<div class="foo bar"></div><span/>`,
3160+
`<div :class="data"></div><span/>`,
3161+
ref('foo'),
3162+
)
3163+
expect(container.innerHTML).toBe('<div class="foo"></div><span></span>')
3164+
expect(`Hydration class mismatch`).toHaveBeenWarned()
31413165
})
31423166
// test('style mismatch', () => {
31433167
// mountWithHydration(`<div style="color:red;"></div>`, () =>

0 commit comments

Comments
 (0)