element-plus/packages/utils/tests/global-nodes.spec.ts
jeremywu 913aaafabb
feat(hooks): add use-teleport hook (#2421)
* feat(hooks) add use-teleport hook
- Add teleport hook for teleported components
- Add teleport hooks hepler methods
- Add coresponding testing cases

* - add use teleport to the exporting entry
2021-07-03 19:04:03 +08:00

47 lines
926 B
TypeScript

import { createGlobalNode, removeGlobalNode, changeGlobalNodesTarget } from '../global-nodes'
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)
})
})