diff --git a/package.json b/package.json index f393818d8..37f4c79e6 100644 --- a/package.json +++ b/package.json @@ -19,9 +19,10 @@ "build:main": "node build/build.main.js", "build:logger": "rollup -c build/rollup.logger.config.js", "lint": "eslint src test", - "test": "npm run lint && npm run test:types && npm run test:unit && npm run test:e2e", + "test": "npm run lint && npm run test:types && npm run test:unit && npm run test:ssr && npm run test:e2e", "test:unit": "rollup -c build/rollup.dev.config.js && jasmine JASMINE_CONFIG_PATH=test/unit/jasmine.json", "test:e2e": "node test/e2e/runner.js", + "test:ssr": "rollup -c build/rollup.dev.config.js && VUE_ENV=server jasmine JASMINE_CONFIG_PATH=test/unit/jasmine.json", "test:types": "tsc -p types/test", "release": "bash build/release.sh", "docs": "cd docs && gitbook serve", diff --git a/test/unit/hot-reload.spec.js b/test/unit/hot-reload.spec.js index 0af283b42..e27526039 100644 --- a/test/unit/hot-reload.spec.js +++ b/test/unit/hot-reload.spec.js @@ -2,6 +2,7 @@ import Vue from 'vue/dist/vue.common.js' import Vuex from '../../dist/vuex.common.js' const TEST = 'TEST' +const isSSR = process.env.VUE_ENV === 'server' describe('Hot Reload', () => { it('mutations', function () { @@ -278,10 +279,14 @@ describe('Hot Reload', () => { expect(vm.a).toBe(10) store.dispatch('check', 10) - Vue.nextTick(() => { - expect(spy).toHaveBeenCalled() + if (isSSR) { done() - }) + } else { + Vue.nextTick(() => { + expect(spy).toHaveBeenCalled() + done() + }) + } }) it('provide warning if a new module is given', () => { diff --git a/test/unit/store.spec.js b/test/unit/store.spec.js index bcc8af987..fdfa04282 100644 --- a/test/unit/store.spec.js +++ b/test/unit/store.spec.js @@ -2,6 +2,7 @@ import Vue from 'vue/dist/vue.common.js' import Vuex from '../../dist/vuex.common.js' const TEST = 'TEST' +const isSSR = process.env.VUE_ENV === 'server' describe('Store', () => { it('committing mutations', () => { @@ -263,77 +264,6 @@ describe('Store', () => { ) }) - it('strict mode: warn mutations outside of handlers', () => { - const store = new Vuex.Store({ - state: { - a: 1 - }, - strict: true - }) - Vue.config.silent = true - expect(() => { store.state.a++ }).toThrow() - Vue.config.silent = false - }) - - it('watch: with resetting vm', done => { - const store = new Vuex.Store({ - state: { - count: 0 - }, - mutations: { - [TEST]: state => state.count++ - } - }) - - const spy = jasmine.createSpy() - store.watch(state => state.count, spy) - - // reset store vm - store.registerModule('test', {}) - - Vue.nextTick(() => { - store.commit(TEST) - expect(store.state.count).toBe(1) - - Vue.nextTick(() => { - expect(spy).toHaveBeenCalled() - done() - }) - }) - }) - - it('watch: getter function has access to store\'s getters object', done => { - const store = new Vuex.Store({ - state: { - count: 0 - }, - mutations: { - [TEST]: state => state.count++ - }, - getters: { - getCount: state => state.count - } - }) - - const getter = function getter (state, getters) { - return state.count - } - const spy = spyOn({ getter }, 'getter').and.callThrough() - const spyCb = jasmine.createSpy() - - store.watch(spy, spyCb) - - Vue.nextTick(() => { - store.commit(TEST) - expect(store.state.count).toBe(1) - - Vue.nextTick(() => { - expect(spy).toHaveBeenCalledWith(store.state, store.getters) - done() - }) - }) - }) - it('asserts the call with the new operator', () => { expect(() => { Vuex.Store({}) @@ -355,4 +285,78 @@ describe('Store', () => { store.commit(TEST, 2) expect(store.state.a).toBe(3) }) + + // store.watch should only be asserted in non-SSR environment + if (!isSSR) { + it('strict mode: warn mutations outside of handlers', () => { + const store = new Vuex.Store({ + state: { + a: 1 + }, + strict: true + }) + Vue.config.silent = true + expect(() => { store.state.a++ }).toThrow() + Vue.config.silent = false + }) + + it('watch: with resetting vm', done => { + const store = new Vuex.Store({ + state: { + count: 0 + }, + mutations: { + [TEST]: state => state.count++ + } + }) + + const spy = jasmine.createSpy() + store.watch(state => state.count, spy) + + // reset store vm + store.registerModule('test', {}) + + Vue.nextTick(() => { + store.commit(TEST) + expect(store.state.count).toBe(1) + + Vue.nextTick(() => { + expect(spy).toHaveBeenCalled() + done() + }) + }) + }) + + it('watch: getter function has access to store\'s getters object', done => { + const store = new Vuex.Store({ + state: { + count: 0 + }, + mutations: { + [TEST]: state => state.count++ + }, + getters: { + getCount: state => state.count + } + }) + + const getter = function getter (state, getters) { + return state.count + } + const spy = spyOn({ getter }, 'getter').and.callThrough() + const spyCb = jasmine.createSpy() + + store.watch(spy, spyCb) + + Vue.nextTick(() => { + store.commit(TEST) + expect(store.state.count).toBe(1) + + Vue.nextTick(() => { + expect(spy).toHaveBeenCalledWith(store.state, store.getters) + done() + }) + }) + }) + } })