mirror of
https://gitee.com/element-plus/element-plus.git
synced 2024-12-04 20:27:44 +08:00
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)
|
||
|
})
|
||
|
})
|