Skip to content

Commit

Permalink
fix(hooks): [use-lockscreen] removing class name at wrong time
Browse files Browse the repository at this point in the history
  • Loading branch information
JauSingSing committed Apr 7, 2024
1 parent 22ac4c5 commit f740ad8
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
27 changes: 27 additions & 0 deletions packages/hooks/__tests__/use-lockscreen.test.tsx
Expand Up @@ -2,6 +2,7 @@ import { computed, 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 sleep from '@element-plus/test-utils/sleep'

import { useLockscreen } from '../use-lockscreen'
import { useNamespace } from '../use-namespace'
Expand Down Expand Up @@ -78,4 +79,30 @@ describe('useLockscreen', () => {

wrapper.unmount()
})

it('should not remove class name when another trigger is true', async () => {
// await the previous test remove class name
await sleep(250)
const trigger = mount({
setup: () => () => <Comp />,
})
const anotherTrigger = mount({
setup: () => () => <Comp />,
})
await nextTick()

expect(hasClass(document.body, kls)).toBe(true)

anotherTrigger.unmount()
await nextTick()
await sleep(250)

expect(hasClass(document.body, kls)).toBe(true)

trigger.unmount()
await nextTick()

await sleep(250)
expect(hasClass(document.body, kls)).toBe(false)
})
})
4 changes: 2 additions & 2 deletions packages/hooks/use-lockscreen/index.ts
Expand Up @@ -57,7 +57,7 @@ export const useLockscreen = (
}
watch(trigger, (val) => {
if (!val) {
cleanup()
withoutHiddenClass && cleanup()
return
}

Expand All @@ -78,5 +78,5 @@ export const useLockscreen = (
}
addClass(document.body, hiddenCls.value)
})
onScopeDispose(() => cleanup())
onScopeDispose(() => withoutHiddenClass && cleanup())
}

0 comments on commit f740ad8

Please sign in to comment.