test(hooks): [use-teleport] add no-client test (#16498)

This commit is contained in:
wzc520pyfm 2024-04-14 11:35:04 +08:00 committed by GitHub
parent 8611a4bc72
commit 84f49de955
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1,6 +1,7 @@
import { defineComponent, h, nextTick, ref } from 'vue'
import { mount } from '@vue/test-utils'
import { afterEach, beforeEach, describe, expect, it } from 'vitest'
import { NOOP } from '@vue/shared'
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
import { useTeleport } from '../use-teleport'
import type { VueWrapper } from '@vue/test-utils'
@ -13,6 +14,7 @@ const Comp = defineComponent({
() => h('div', AXIOM),
appendToBody
)
showTeleport()
return () => (
<>
@ -73,3 +75,29 @@ describe('useTeleport', () => {
expect(wrapper.text()).toContain(AXIOM)
})
})
describe('useTeleport when isClient is false', () => {
const mockIsClient = false
beforeEach(() => {
vi.resetModules()
vi.doMock('@element-plus/utils', () => ({
isClient: mockIsClient,
}))
})
afterEach(() => {
vi.doUnmock('@element-plus/utils')
})
it('should get default value when isClient is false', async () => {
const { useTeleport: mockUseTeleport } = await import('../use-teleport')
const appendToBody = ref(true)
const { isTeleportVisible, showTeleport, hideTeleport, renderTeleport } =
mockUseTeleport(() => h('div', AXIOM), appendToBody)
expect(isTeleportVisible.value).toBeFalsy()
expect(showTeleport).toEqual(NOOP)
expect(hideTeleport).toEqual(NOOP)
expect(renderTeleport).toEqual(NOOP)
})
})