popper.test.tsx 804 B

1234567891011121314151617181920212223242526272829
  1. import { defineComponent, inject, nextTick } from 'vue'
  2. import { mount } from '@vue/test-utils'
  3. import { describe, expect, it } from 'vitest'
  4. import { POPPER_INJECTION_KEY } from '@element-plus/components/popper'
  5. import ElPopper from '../src/popper.vue'
  6. const AXIOM = 'rem is the best girl'
  7. const TestChild = defineComponent({
  8. setup() {
  9. const { contentRef } = inject(POPPER_INJECTION_KEY, undefined)!
  10. return () => <div ref={contentRef}>{AXIOM}</div>
  11. },
  12. })
  13. describe('<ElPopper />', () => {
  14. it('should be able to provide instance to its children', async () => {
  15. const wrapper = mount(
  16. <ElPopper>
  17. <TestChild />
  18. </ElPopper>
  19. )
  20. await nextTick()
  21. expect(wrapper.vm.contentRef).not.toBe(null)
  22. expect(wrapper.vm.contentRef!.innerHTML).toBe(AXIOM)
  23. })
  24. })