element-plus/packages/hooks/__tests__/use-z-index.test.tsx
qiang 1621b6a2d5
fix(hooks): SSR hydration error caused by z-index (#16175)
* fix(hooks): SSR hydration error caused by z-index

* test(hooks): test error

* chore: optimize name

* update

Co-authored-by: btea <2356281422@qq.com>

---------

Co-authored-by: btea <2356281422@qq.com>
2024-03-22 16:36:25 +08:00

59 lines
1.4 KiB
TypeScript

import { config, mount } from '@vue/test-utils'
import { afterEach, beforeEach, describe, expect, it } from 'vitest'
import { ZINDEX_INJECTION_KEY, useZIndex } from '../use-z-index'
describe('no injection value', () => {
afterEach(() => {
document.body.innerHTML = ''
})
it('useZIndex', () => {
const wrapper = mount({
setup() {
const { initialZIndex, currentZIndex, nextZIndex } = useZIndex()
return { initialZIndex, currentZIndex, nextZIndex: nextZIndex() }
},
render: () => undefined,
})
expect(wrapper.vm.initialZIndex).toBe(2000)
expect(wrapper.vm.currentZIndex).toBe(2001)
expect(wrapper.vm.nextZIndex).toBe(2001)
})
})
describe('with injection value', () => {
beforeEach(() => {
config.global.provide = {
[ZINDEX_INJECTION_KEY as symbol]: {
current: 10,
},
}
})
afterEach(() => {
document.body.innerHTML = ''
config.global.provide = {}
})
it('useZIndex', () => {
const wrapper = mount({
setup() {
const { initialZIndex, currentZIndex, nextZIndex } = useZIndex()
nextZIndex()
return {
initialZIndex,
currentZIndex,
nextZIndex: nextZIndex(),
}
},
render: () => undefined,
})
expect(wrapper.vm.initialZIndex).toBe(2000)
expect(wrapper.vm.currentZIndex).toBe(2012)
expect(wrapper.vm.nextZIndex).toBe(2012)
})
})