Skip to content

Commit c9725cb

Browse files
committed
fix(plugins): allow setting custom plugin and vuex/router
1 parent 0c1bff6 commit c9725cb

File tree

2 files changed

+45
-10
lines changed

2 files changed

+45
-10
lines changed

src/__tests__/plugins.js

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
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+
})

src/index.js

+6-10
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
/* eslint-disable testing-library/no-wait-for-empty-callback */
22
import {mount} from '@vue/test-utils'
3-
import merge from 'lodash.merge'
43

54
import {
65
getQueriesForElement,
@@ -25,7 +24,7 @@ function render(
2524
const baseElement = customBaseElement || customContainer || document.body
2625
const container = customContainer || baseElement.appendChild(div)
2726

28-
const plugins = []
27+
const plugins = mountOptions.global?.plugins || []
2928

3029
if (store) {
3130
const {createStore} = require('vuex')
@@ -41,14 +40,11 @@ function render(
4140
plugins.push(routerPlugin)
4241
}
4342

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+
})
5248

5349
// this removes the additional "data-v-app" div node from VTU:
5450
// https://github.com/vuejs/vue-test-utils-next/blob/master/src/mount.ts#L196-L213

0 commit comments

Comments
 (0)