File tree 3 files changed +34
-2
lines changed
3 files changed +34
-2
lines changed Original file line number Diff line number Diff line change 1
1
import '@testing-library/jest-dom'
2
2
import { render , fireEvent } from '@testing-library/vue'
3
+ import Vuex from 'vuex'
3
4
4
5
import VuexTest from './components/Store/VuexTest'
5
6
import { store } from './components/Store/store'
@@ -54,3 +55,33 @@ test('can render with vuex with custom store', async () => {
54
55
await fireEvent . click ( getByText ( '-' ) )
55
56
expect ( getByTestId ( 'count-value' ) ) . toHaveTextContent ( '1000' )
56
57
} )
58
+
59
+ test ( 'can render with an instantiated Vuex store' , async ( ) => {
60
+ const { getByTestId, getByText} = render ( VuexTest , {
61
+ store : new Vuex . Store ( {
62
+ state : { count : 3 } ,
63
+ mutations : {
64
+ increment ( state ) {
65
+ state . count ++
66
+ } ,
67
+ decrement ( state ) {
68
+ state . count --
69
+ } ,
70
+ } ,
71
+ actions : {
72
+ increment ( context ) {
73
+ context . commit ( 'increment' )
74
+ } ,
75
+ decrement ( context ) {
76
+ context . commit ( 'decrement' )
77
+ } ,
78
+ } ,
79
+ } ) ,
80
+ } )
81
+
82
+ await fireEvent . click ( getByText ( '+' ) )
83
+ expect ( getByTestId ( 'count-value' ) ) . toHaveTextContent ( '4' )
84
+
85
+ await fireEvent . click ( getByText ( '-' ) )
86
+ expect ( getByTestId ( 'count-value' ) ) . toHaveTextContent ( '3' )
87
+ } )
Original file line number Diff line number Diff line change @@ -31,7 +31,7 @@ function render(
31
31
const Vuex = require ( 'vuex' )
32
32
localVue . use ( Vuex )
33
33
34
- vuexStore = new Vuex . Store ( store )
34
+ vuexStore = store instanceof Vuex . Store ? store : new Vuex . Store ( store )
35
35
}
36
36
37
37
if ( routes ) {
Original file line number Diff line number Diff line change @@ -40,7 +40,8 @@ export interface RenderOptions<V extends Vue, S = {}>
40
40
// The props and store options special-cased by Vue Testing Library and NOT passed to mount().
41
41
extends Omit < ThisTypedMountOptions < V > , 'store' | 'props' > {
42
42
props ?: object
43
- store ?: StoreOptions < S >
43
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
44
+ store ?: StoreOptions < S > | Store < any >
44
45
routes ?: RouteConfig [ ]
45
46
container ?: Element
46
47
baseElement ?: Element
You can’t perform that action at this time.
0 commit comments