@@ -39,6 +39,31 @@ describe('Helpers', () => {
3939 expect ( vm . a ) . toBe ( 4 )
4040 } )
4141
42+ it ( 'mapState (with namespace)' , ( ) => {
43+ const store = new Vuex . Store ( {
44+ modules : {
45+ foo : {
46+ namespaced : true ,
47+ state : { a : 1 } ,
48+ getters : {
49+ b : state => state . a + 1
50+ }
51+ }
52+ }
53+ } )
54+ const vm = new Vue ( {
55+ store,
56+ computed : mapState ( 'foo' , {
57+ a : ( state , getters ) => {
58+ return state . a + getters . b
59+ }
60+ } )
61+ } )
62+ expect ( vm . a ) . toBe ( 3 )
63+ store . state . foo . a ++
64+ expect ( vm . a ) . toBe ( 5 )
65+ } )
66+
4267 it ( 'mapMutations (array)' , ( ) => {
4368 const store = new Vuex . Store ( {
4469 state : { count : 0 } ,
@@ -78,6 +103,32 @@ describe('Helpers', () => {
78103 expect ( store . state . count ) . toBe ( 0 )
79104 } )
80105
106+ it ( 'mapMutations (with namespace)' , ( ) => {
107+ const store = new Vuex . Store ( {
108+ modules : {
109+ foo : {
110+ namespaced : true ,
111+ state : { count : 0 } ,
112+ mutations : {
113+ inc : state => state . count ++ ,
114+ dec : state => state . count --
115+ }
116+ }
117+ }
118+ } )
119+ const vm = new Vue ( {
120+ store,
121+ methods : mapMutations ( 'foo' , {
122+ plus : 'inc' ,
123+ minus : 'dec'
124+ } )
125+ } )
126+ vm . plus ( )
127+ expect ( store . state . foo . count ) . toBe ( 1 )
128+ vm . minus ( )
129+ expect ( store . state . foo . count ) . toBe ( 0 )
130+ } )
131+
81132 it ( 'mapGetters (array)' , ( ) => {
82133 const store = new Vuex . Store ( {
83134 state : { count : 0 } ,
@@ -135,6 +186,41 @@ describe('Helpers', () => {
135186 expect ( vm . b ) . toBe ( true )
136187 } )
137188
189+ it ( 'mapGetters (with namespace)' , ( ) => {
190+ const store = new Vuex . Store ( {
191+ modules : {
192+ foo : {
193+ namespaced : true ,
194+ state : { count : 0 } ,
195+ mutations : {
196+ inc : state => state . count ++ ,
197+ dec : state => state . count --
198+ } ,
199+ getters : {
200+ hasAny : ( { count } ) => count > 0 ,
201+ negative : ( { count } ) => count < 0
202+ }
203+ }
204+ }
205+ } )
206+ const vm = new Vue ( {
207+ store,
208+ computed : mapGetters ( 'foo' , {
209+ a : 'hasAny' ,
210+ b : 'negative'
211+ } )
212+ } )
213+ expect ( vm . a ) . toBe ( false )
214+ expect ( vm . b ) . toBe ( false )
215+ store . commit ( 'foo/inc' )
216+ expect ( vm . a ) . toBe ( true )
217+ expect ( vm . b ) . toBe ( false )
218+ store . commit ( 'foo/dec' )
219+ store . commit ( 'foo/dec' )
220+ expect ( vm . a ) . toBe ( false )
221+ expect ( vm . b ) . toBe ( true )
222+ } )
223+
138224 it ( 'mapActions (array)' , ( ) => {
139225 const a = jasmine . createSpy ( )
140226 const b = jasmine . createSpy ( )
@@ -177,4 +263,32 @@ describe('Helpers', () => {
177263 vm . bar ( )
178264 expect ( b ) . toHaveBeenCalled ( )
179265 } )
266+
267+ it ( 'mapActions (with namespace)' , ( ) => {
268+ const a = jasmine . createSpy ( )
269+ const b = jasmine . createSpy ( )
270+ const store = new Vuex . Store ( {
271+ modules : {
272+ foo : {
273+ namespaced : true ,
274+ actions : {
275+ a,
276+ b
277+ }
278+ }
279+ }
280+ } )
281+ const vm = new Vue ( {
282+ store,
283+ methods : mapActions ( 'foo/' , {
284+ foo : 'a' ,
285+ bar : 'b'
286+ } )
287+ } )
288+ vm . foo ( )
289+ expect ( a ) . toHaveBeenCalled ( )
290+ expect ( b ) . not . toHaveBeenCalled ( )
291+ vm . bar ( )
292+ expect ( b ) . toHaveBeenCalled ( )
293+ } )
180294} )
0 commit comments