|
| 1 | +import ElementPlus from 'element-plus' |
| 2 | +import {defineComponent} from 'vue' |
| 3 | +import userEvent from '@testing-library/user-event' |
| 4 | +import '@testing-library/jest-dom' |
| 5 | +import {render, screen, waitFor} from '..' |
| 6 | + |
| 7 | +const Component = defineComponent({ |
| 8 | + template: ` |
| 9 | + <el-popover trigger="hover" content="this is content"> |
| 10 | + <template #reference> |
| 11 | + <el-button>Hover to activate</el-button> |
| 12 | + </template> |
| 13 | + </el-popover> |
| 14 | + `, |
| 15 | +}) |
| 16 | + |
| 17 | +test('Stubs out a component', async () => { |
| 18 | + render(Component, { |
| 19 | + global: { |
| 20 | + plugins: [ElementPlus], |
| 21 | + }, |
| 22 | + }) |
| 23 | + |
| 24 | + const button = screen.getByText('Hover to activate') |
| 25 | + const getContent = () => screen.getByText('this is content') |
| 26 | + |
| 27 | + expect(getContent()).toBeInTheDocument() |
| 28 | + expect(getContent()).not.toBeVisible() |
| 29 | + |
| 30 | + userEvent.hover(button) |
| 31 | + |
| 32 | + await waitFor(() => expect(getContent()).toBeVisible()) |
| 33 | + |
| 34 | + userEvent.unhover(button) |
| 35 | + |
| 36 | + await waitFor(() => expect(getContent()).not.toBeVisible()) |
| 37 | +}) |
0 commit comments