File tree Expand file tree Collapse file tree 3 files changed +57
-1
lines changed Expand file tree Collapse file tree 3 files changed +57
-1
lines changed Original file line number Diff line number Diff line change 11import '@testing-library/jest-dom'
22import { render , fireEvent } from '@testing-library/vue'
3+ import Vuex from 'vuex'
34
45import VuexTest from './components/Store/VuexTest'
56import { store } from './components/Store/store'
@@ -54,3 +55,33 @@ test('can render with vuex with custom store', async () => {
5455 await fireEvent . click ( getByText ( '-' ) )
5556 expect ( getByTestId ( 'count-value' ) ) . toHaveTextContent ( '1000' )
5657} )
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(
3131 const Vuex = require ( 'vuex' )
3232 localVue . use ( Vuex )
3333
34- vuexStore = new Vuex . Store ( store )
34+ vuexStore = store instanceof Vuex . Store ? store : new Vuex . Store ( store )
3535 }
3636
3737 if ( routes ) {
Original file line number Diff line number Diff line change 11import Vue from 'vue'
2+ import Vuex from 'vuex'
23import { render , fireEvent , screen , waitFor } from '@testing-library/vue'
34
45declare const elem : Element
@@ -127,6 +128,30 @@ export function testConfigCallback() {
127128 } )
128129}
129130
131+ export function testInstantiatedStore ( ) {
132+ render ( SomeComponent , {
133+ store : new Vuex . Store ( {
134+ state : { count : 3 } ,
135+ mutations : {
136+ increment ( state ) {
137+ state . count ++
138+ } ,
139+ decrement ( state ) {
140+ state . count --
141+ } ,
142+ } ,
143+ actions : {
144+ increment ( context ) {
145+ context . commit ( 'increment' )
146+ } ,
147+ decrement ( context ) {
148+ context . commit ( 'decrement' )
149+ } ,
150+ } ,
151+ } ) ,
152+ } )
153+ }
154+
130155/*
131156eslint
132157 testing-library/prefer-explicit-assert: "off",
You can’t perform that action at this time.
0 commit comments