File tree 2 files changed +45
-10
lines changed
2 files changed +45
-10
lines changed Original file line number Diff line number Diff line change
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 ( 'setting a plugin + a custom option such as store sets both plugins' , 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
+ ` ,
20
+ } )
21
+
22
+ render ( ComponentWithStore , {
23
+ store,
24
+ global : {
25
+ plugins : [ ElementPlus ] ,
26
+ } ,
27
+ } )
28
+
29
+ const button = screen . getByText ( 'Hover to activate' )
30
+ userEvent . hover ( button )
31
+
32
+ await waitFor ( ( ) => expect ( screen . getByText ( 'this is content' ) ) . toBeVisible ( ) )
33
+
34
+ expect ( screen . getByTestId ( 'count-value' ) ) . toHaveTextContent ( '0' )
35
+
36
+ await fireEvent . click ( button )
37
+
38
+ expect ( screen . getByTestId ( 'count-value' ) ) . toHaveTextContent ( '1' )
39
+ } )
Original file line number Diff line number Diff line change 1
1
/* eslint-disable testing-library/no-wait-for-empty-callback */
2
2
import { mount } from '@vue/test-utils'
3
- import merge from 'lodash.merge'
4
3
5
4
import {
6
5
getQueriesForElement ,
@@ -25,7 +24,7 @@ function render(
25
24
const baseElement = customBaseElement || customContainer || document . body
26
25
const container = customContainer || baseElement . appendChild ( div )
27
26
28
- const plugins = [ ]
27
+ const plugins = mountOptions . global ?. plugins || [ ]
29
28
30
29
if ( store ) {
31
30
const { createStore} = require ( 'vuex' )
@@ -41,14 +40,11 @@ function render(
41
40
plugins . push ( routerPlugin )
42
41
}
43
42
44
- const wrapper = mount (
45
- Component ,
46
- merge ( {
47
- attachTo : container ,
48
- global : { plugins} ,
49
- ...mountOptions ,
50
- } ) ,
51
- )
43
+ const wrapper = mount ( Component , {
44
+ attachTo : container ,
45
+ global : { plugins} ,
46
+ ...mountOptions ,
47
+ } )
52
48
53
49
// this removes the additional "data-v-app" div node from VTU:
54
50
// https://github.com/vuejs/vue-test-utils-next/blob/master/src/mount.ts#L196-L213
You can’t perform that action at this time.
0 commit comments