mirror of
https://github.com/element-plus/element-plus.git
synced 2025-02-23 11:59:34 +08:00
test(hooks): [use-teleport] add no-client test (#16498)
This commit is contained in:
parent
8611a4bc72
commit
84f49de955
@ -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)
|
||||
})
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user