popconfirm.test.tsx 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. import { nextTick } from 'vue'
  2. import { mount } from '@vue/test-utils'
  3. import { afterEach, describe, expect, it } from 'vitest'
  4. import { rAF } from '@element-plus/test-utils/tick'
  5. import { usePopperContainerId } from '@element-plus/hooks'
  6. import Popconfirm from '../src/popconfirm.vue'
  7. const AXIOM = 'rem is the best girl'
  8. const selector = '.el-popper'
  9. describe('Popconfirm.vue', () => {
  10. afterEach(() => {
  11. document.body.innerHTML = ''
  12. })
  13. it('render test', async () => {
  14. const wrapper = mount(() => (
  15. <>
  16. <Popconfirm
  17. attachTo="body"
  18. v-slots={{
  19. reference: () => <div class="reference">{AXIOM}</div>,
  20. }}
  21. />
  22. </>
  23. ))
  24. await nextTick()
  25. expect(document.querySelector(selector)!.getAttribute('style')).toContain(
  26. 'display: none'
  27. )
  28. await wrapper.find('.reference').trigger('click')
  29. await nextTick()
  30. await rAF()
  31. expect(
  32. document.querySelector(selector)!.getAttribute('style')
  33. ).not.toContain('display: none')
  34. })
  35. describe('teleported API', () => {
  36. it('should mount on popper container', async () => {
  37. expect(document.body.innerHTML).toBe('')
  38. mount(() => (
  39. <>
  40. <Popconfirm
  41. attachTo="body"
  42. v-slots={{
  43. reference: () => <div class="reference">{AXIOM}</div>,
  44. }}
  45. />
  46. </>
  47. ))
  48. await nextTick()
  49. const { selector } = usePopperContainerId()
  50. expect(document.body.querySelector(selector.value)!.innerHTML).not.toBe(
  51. ''
  52. )
  53. })
  54. it('should not mount on the popper container', async () => {
  55. expect(document.body.innerHTML).toBe('')
  56. mount(() => (
  57. <>
  58. <Popconfirm
  59. attachTo="body"
  60. teleported={false}
  61. v-slots={{
  62. reference: () => <div class="reference">{AXIOM}</div>,
  63. }}
  64. />
  65. </>
  66. ))
  67. await nextTick()
  68. const { selector } = usePopperContainerId()
  69. expect(document.body.querySelector(selector.value)!.innerHTML).toBe('')
  70. })
  71. })
  72. })