element-plus/packages/utils/tests/vue/global-nodes.spec.ts
三咲智子 6503e55277
refactor(utils): migrate utils (#5949)
* refactor(utils-v2): migrate utils

* refactor(utils-v2): migrate utils

* refactor(utils-v2): migrate utils

* refactor(utils): remove

* refactor(utils): rename

* refactor(utils): move EVENT_CODE to constants

* refactor: remove generic
2022-02-11 11:03:15 +08:00

44 lines
916 B
TypeScript

import {
createGlobalNode,
removeGlobalNode,
changeGlobalNodesTarget,
} from '../..'
describe('global-nodes', () => {
afterEach(() => {
document.body.innerHTML = ''
})
it('should create nodes to the root element', () => {
const el = createGlobalNode()
expect(el).not.toBeNull()
expect(document.body.firstChild).toBe(el)
})
it('should remove the recent created element', () => {
const el = createGlobalNode()
expect(document.body.firstElementChild).toBe(el)
removeGlobalNode(el)
expect(document.body.children).toHaveLength(0)
})
it('should change the target of created element', () => {
const target = createGlobalNode()
expect(document.body.firstElementChild).toBe(target)
const el = createGlobalNode()
expect(el.parentElement).toBe(document.body)
changeGlobalNodesTarget(target)
expect(el.parentElement).toBe(target)
})
})