mirror of
https://gitee.com/element-plus/element-plus.git
synced 2024-12-15 01:41:20 +08:00
1d13ebb05d
* feat: drop jest * test: remove ssr * test: rename * chore: update tsconfig
51 lines
1.2 KiB
TypeScript
51 lines
1.2 KiB
TypeScript
import { defineComponent, nextTick, onMounted, ref } from 'vue'
|
|
import { mount } from '@vue/test-utils'
|
|
import { describe, expect, it } from 'vitest'
|
|
import { hasClass } from '@element-plus/utils'
|
|
|
|
import { useLockscreen } from '../use-lockscreen'
|
|
|
|
const kls = 'el-popup-parent--hidden'
|
|
|
|
const Comp = defineComponent({
|
|
setup() {
|
|
const flag = ref(false)
|
|
useLockscreen(flag)
|
|
onMounted(() => {
|
|
flag.value = true
|
|
})
|
|
|
|
return () => undefined
|
|
},
|
|
})
|
|
|
|
describe('useLockscreen', () => {
|
|
it('should lock screen when trigger is true', async () => {
|
|
const wrapper = mount({
|
|
setup: () => () => <Comp />,
|
|
})
|
|
await nextTick()
|
|
expect(hasClass(document.body, kls)).toBe(true)
|
|
|
|
wrapper.unmount()
|
|
await nextTick()
|
|
expect(hasClass(document.body, kls)).toBe(false)
|
|
})
|
|
|
|
it('should cleanup when unmounted', async () => {
|
|
const shouldRender = ref(true)
|
|
mount({
|
|
setup: () => () => shouldRender.value ? <Comp /> : undefined,
|
|
})
|
|
|
|
await nextTick()
|
|
|
|
expect(hasClass(document.body, kls)).toBe(true)
|
|
|
|
shouldRender.value = false
|
|
await nextTick()
|
|
|
|
expect(hasClass(document.body, kls)).toBe(false)
|
|
})
|
|
})
|