element-plus/packages/utils/__tests__/vue/global-node.vitest.ts
三咲智子 aaf90d99d0
test: switch to vitest (#5991)
* test: use vitest

* test: add script and ci

* chore: improve tsconfig

* refactor: use-form-item

* fix: remove unused

* chore: improve scripts

* test: improve mock

* refactor: change coverage
2022-02-21 14:28:22 +08:00

45 lines
973 B
TypeScript

import { describe, it, expect, afterEach } from 'vitest'
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)
})
})