@@ -2,6 +2,7 @@ import Vue from 'vue/dist/vue.common.js'
22import Vuex from '../../dist/vuex.common.js'
33
44const TEST = 'TEST'
5+ const isSSR = process . env . VUE_ENV === 'server'
56
67describe ( 'Store' , ( ) => {
78 it ( 'committing mutations' , ( ) => {
@@ -263,77 +264,6 @@ describe('Store', () => {
263264 )
264265 } )
265266
266- it ( 'strict mode: warn mutations outside of handlers' , ( ) => {
267- const store = new Vuex . Store ( {
268- state : {
269- a : 1
270- } ,
271- strict : true
272- } )
273- Vue . config . silent = true
274- expect ( ( ) => { store . state . a ++ } ) . toThrow ( )
275- Vue . config . silent = false
276- } )
277-
278- it ( 'watch: with resetting vm' , done => {
279- const store = new Vuex . Store ( {
280- state : {
281- count : 0
282- } ,
283- mutations : {
284- [ TEST ] : state => state . count ++
285- }
286- } )
287-
288- const spy = jasmine . createSpy ( )
289- store . watch ( state => state . count , spy )
290-
291- // reset store vm
292- store . registerModule ( 'test' , { } )
293-
294- Vue . nextTick ( ( ) => {
295- store . commit ( TEST )
296- expect ( store . state . count ) . toBe ( 1 )
297-
298- Vue . nextTick ( ( ) => {
299- expect ( spy ) . toHaveBeenCalled ( )
300- done ( )
301- } )
302- } )
303- } )
304-
305- it ( 'watch: getter function has access to store\'s getters object' , done => {
306- const store = new Vuex . Store ( {
307- state : {
308- count : 0
309- } ,
310- mutations : {
311- [ TEST ] : state => state . count ++
312- } ,
313- getters : {
314- getCount : state => state . count
315- }
316- } )
317-
318- const getter = function getter ( state , getters ) {
319- return state . count
320- }
321- const spy = spyOn ( { getter } , 'getter' ) . and . callThrough ( )
322- const spyCb = jasmine . createSpy ( )
323-
324- store . watch ( spy , spyCb )
325-
326- Vue . nextTick ( ( ) => {
327- store . commit ( TEST )
328- expect ( store . state . count ) . toBe ( 1 )
329-
330- Vue . nextTick ( ( ) => {
331- expect ( spy ) . toHaveBeenCalledWith ( store . state , store . getters )
332- done ( )
333- } )
334- } )
335- } )
336-
337267 it ( 'asserts the call with the new operator' , ( ) => {
338268 expect ( ( ) => {
339269 Vuex . Store ( { } )
@@ -355,4 +285,78 @@ describe('Store', () => {
355285 store . commit ( TEST , 2 )
356286 expect ( store . state . a ) . toBe ( 3 )
357287 } )
288+
289+ // store.watch should only be asserted in non-SSR environment
290+ if ( ! isSSR ) {
291+ it ( 'strict mode: warn mutations outside of handlers' , ( ) => {
292+ const store = new Vuex . Store ( {
293+ state : {
294+ a : 1
295+ } ,
296+ strict : true
297+ } )
298+ Vue . config . silent = true
299+ expect ( ( ) => { store . state . a ++ } ) . toThrow ( )
300+ Vue . config . silent = false
301+ } )
302+
303+ it ( 'watch: with resetting vm' , done => {
304+ const store = new Vuex . Store ( {
305+ state : {
306+ count : 0
307+ } ,
308+ mutations : {
309+ [ TEST ] : state => state . count ++
310+ }
311+ } )
312+
313+ const spy = jasmine . createSpy ( )
314+ store . watch ( state => state . count , spy )
315+
316+ // reset store vm
317+ store . registerModule ( 'test' , { } )
318+
319+ Vue . nextTick ( ( ) => {
320+ store . commit ( TEST )
321+ expect ( store . state . count ) . toBe ( 1 )
322+
323+ Vue . nextTick ( ( ) => {
324+ expect ( spy ) . toHaveBeenCalled ( )
325+ done ( )
326+ } )
327+ } )
328+ } )
329+
330+ it ( 'watch: getter function has access to store\'s getters object' , done => {
331+ const store = new Vuex . Store ( {
332+ state : {
333+ count : 0
334+ } ,
335+ mutations : {
336+ [ TEST ] : state => state . count ++
337+ } ,
338+ getters : {
339+ getCount : state => state . count
340+ }
341+ } )
342+
343+ const getter = function getter ( state , getters ) {
344+ return state . count
345+ }
346+ const spy = spyOn ( { getter } , 'getter' ) . and . callThrough ( )
347+ const spyCb = jasmine . createSpy ( )
348+
349+ store . watch ( spy , spyCb )
350+
351+ Vue . nextTick ( ( ) => {
352+ store . commit ( TEST )
353+ expect ( store . state . count ) . toBe ( 1 )
354+
355+ Vue . nextTick ( ( ) => {
356+ expect ( spy ) . toHaveBeenCalledWith ( store . state , store . getters )
357+ done ( )
358+ } )
359+ } )
360+ } )
361+ }
358362} )
0 commit comments