2022-03-25 15:35:56 +08:00
|
|
|
import { afterEach, describe, expect, it } from 'vitest'
|
2021-09-04 19:29:28 +08:00
|
|
|
import {
|
2022-03-25 15:35:56 +08:00
|
|
|
changeGlobalNodesTarget,
|
2021-09-04 19:29:28 +08:00
|
|
|
createGlobalNode,
|
|
|
|
removeGlobalNode,
|
2022-02-11 11:03:15 +08:00
|
|
|
} from '../..'
|
2021-07-03 19:04:03 +08:00
|
|
|
|
|
|
|
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)
|
|
|
|
})
|
|
|
|
})
|