|
| 1 | +import '@testing-library/jest-dom' |
| 2 | +import ElementPlus from 'element-plus' |
| 3 | +import userEvent from '@testing-library/user-event' |
| 4 | +import {defineComponent} from 'vue' |
| 5 | +import {render, screen, fireEvent, waitFor} from '..' |
| 6 | +import {store} from './components/Store/store' |
| 7 | + |
| 8 | +test('can set global options and custom options such as a store', async () => { |
| 9 | + const ComponentWithStore = defineComponent({ |
| 10 | + template: ` |
| 11 | + <el-popover trigger="hover" content="this is content"> |
| 12 | + <template #reference> |
| 13 | + <el-button @click="$store.dispatch('increment')"> |
| 14 | + Hover to activate |
| 15 | + </el-button> |
| 16 | + </template> |
| 17 | + </el-popover> |
| 18 | + <span data-testid="count-value">{{ $store.state.count }}</span> |
| 19 | + <directive /> |
| 20 | + `, |
| 21 | + }) |
| 22 | + |
| 23 | + const DirectiveStub = { |
| 24 | + template: '<p>Search now</p>', |
| 25 | + } |
| 26 | + |
| 27 | + render(ComponentWithStore, { |
| 28 | + store, |
| 29 | + global: { |
| 30 | + plugins: [ElementPlus], |
| 31 | + stubs: { |
| 32 | + Directive: DirectiveStub, |
| 33 | + }, |
| 34 | + }, |
| 35 | + }) |
| 36 | + |
| 37 | + expect(screen.getByText('Search now')).toBeInTheDocument() |
| 38 | + |
| 39 | + const button = screen.getByText('Hover to activate') |
| 40 | + userEvent.hover(button) |
| 41 | + |
| 42 | + await waitFor(() => expect(screen.getByText('this is content')).toBeVisible()) |
| 43 | + |
| 44 | + expect(screen.getByTestId('count-value')).toHaveTextContent('0') |
| 45 | + |
| 46 | + await fireEvent.click(button) |
| 47 | + |
| 48 | + expect(screen.getByTestId('count-value')).toHaveTextContent('1') |
| 49 | +}) |
0 commit comments