diff --git a/packages/hooks/__tests__/use-lockscreen.test.tsx b/packages/hooks/__tests__/use-lockscreen.test.tsx index 813f075ad1..c041051f36 100644 --- a/packages/hooks/__tests__/use-lockscreen.test.tsx +++ b/packages/hooks/__tests__/use-lockscreen.test.tsx @@ -29,7 +29,10 @@ describe('useLockscreen', () => { wrapper.unmount() await nextTick() - expect(hasClass(document.body, kls)).toBe(false) + + setTimeout(() => { + expect(hasClass(document.body, kls)).toBe(false) + }, 250) }) it('should cleanup when unmounted', async () => { @@ -45,6 +48,8 @@ describe('useLockscreen', () => { shouldRender.value = false await nextTick() - expect(hasClass(document.body, kls)).toBe(false) + setTimeout(() => { + expect(hasClass(document.body, kls)).toBe(false) + }, 250) }) }) diff --git a/packages/hooks/use-lockscreen/index.ts b/packages/hooks/use-lockscreen/index.ts index 484dbc91b3..41999acafd 100644 --- a/packages/hooks/use-lockscreen/index.ts +++ b/packages/hooks/use-lockscreen/index.ts @@ -1,5 +1,4 @@ import { isRef, onScopeDispose, watch } from 'vue' - import { computed } from '@vue/reactivity' import { isClient } from '@vueuse/core' import { @@ -40,10 +39,12 @@ export const useLockscreen = (trigger: Ref) => { let bodyWidth = '0' const cleanup = () => { - removeClass(document.body, hiddenCls.value) - if (withoutHiddenClass) { - document.body.style.width = bodyWidth - } + setTimeout(() => { + removeClass(document.body, hiddenCls.value) + if (withoutHiddenClass) { + document.body.style.width = bodyWidth + } + }, 200) } watch(trigger, (val) => { if (!val) {