mirror of
https://gitee.com/element-plus/element-plus.git
synced 2024-12-04 04:08:34 +08:00
1621b6a2d5
* 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>
59 lines
1.4 KiB
TypeScript
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)
|
|
})
|
|
})
|