global-node.test.ts 973 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. import { afterEach, describe, expect, it } from 'vitest'
  2. import {
  3. changeGlobalNodesTarget,
  4. createGlobalNode,
  5. removeGlobalNode,
  6. } from '../..'
  7. describe('global-nodes', () => {
  8. afterEach(() => {
  9. document.body.innerHTML = ''
  10. })
  11. it('should create nodes to the root element', () => {
  12. const el = createGlobalNode()
  13. expect(el).not.toBeNull()
  14. expect(document.body.firstChild).toBe(el)
  15. })
  16. it('should remove the recent created element', () => {
  17. const el = createGlobalNode()
  18. expect(document.body.firstElementChild).toBe(el)
  19. removeGlobalNode(el)
  20. expect(document.body.children).toHaveLength(0)
  21. })
  22. it('should change the target of created element', () => {
  23. const target = createGlobalNode()
  24. expect(document.body.firstElementChild).toBe(target)
  25. const el = createGlobalNode()
  26. expect(el.parentElement).toBe(document.body)
  27. changeGlobalNodesTarget(target)
  28. expect(el.parentElement).toBe(target)
  29. })
  30. })