mirror of
https://gitee.com/element-plus/element-plus.git
synced 2024-12-10 07:07:56 +08:00
bbd16a08e9
* refactor(hooks): remove use-css-var * refactor(hooks): remove use-events * refactor(hooks): remove use-migrating * refactor(hooks): remove use-transition * refactor(hooks): named export useAttrs * refactor(hooks): named export useFocus * refactor(hooks): refactor useFormItem * refactor(hooks): refactor useGlobalConfig * refactor(hooks): refactor useLocale * refactor(hooks): refactor useLockscreen * refactor(hooks): refactor useModal * refactor(hooks): refactor useModelToggle * refactor(hooks): refactor usePreventGlobal * refactor(hooks): refactor useRestoreActive * refactor(hooks): refactor useTeleport * refactor(hooks): refactor useThrottleRender * refactor(hooks): refactor useTimeout * refactor(hooks): refactor useTransitionFallthrogh
63 lines
1.3 KiB
TypeScript
63 lines
1.3 KiB
TypeScript
import { ref, nextTick, defineComponent, onMounted } from 'vue'
|
|
import { mount } from '@vue/test-utils'
|
|
import { hasClass } from '@element-plus/utils/dom'
|
|
|
|
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
|
|
})
|
|
},
|
|
template: `<div></div>`,
|
|
})
|
|
|
|
describe('useLockscreen', () => {
|
|
test('should lock screen when trigger is true', async () => {
|
|
const wrapper = mount({
|
|
template: `
|
|
<test-comp />
|
|
`,
|
|
components: {
|
|
'test-comp': Comp,
|
|
},
|
|
})
|
|
await nextTick()
|
|
expect(hasClass(document.body, kls)).toBe(true)
|
|
|
|
wrapper.unmount()
|
|
await nextTick()
|
|
expect(hasClass(document.body, kls)).toBe(false)
|
|
})
|
|
|
|
test('should cleanup when unmounted', async () => {
|
|
const wrapper = mount({
|
|
template: `
|
|
<test-comp v-if="shouldRender" />
|
|
`,
|
|
data() {
|
|
return {
|
|
shouldRender: true,
|
|
}
|
|
},
|
|
components: {
|
|
'test-comp': Comp,
|
|
},
|
|
})
|
|
|
|
await nextTick()
|
|
|
|
expect(hasClass(document.body, kls)).toBe(true)
|
|
|
|
wrapper.vm.shouldRender = false
|
|
await nextTick()
|
|
|
|
expect(hasClass(document.body, kls)).toBe(false)
|
|
})
|
|
})
|