diff --git a/src/store.js b/src/store.js index f540586f2..121706d0b 100644 --- a/src/store.js +++ b/src/store.js @@ -9,6 +9,7 @@ export class Store { constructor (options = {}) { assert(Vue, `must call Vue.use(Vuex) before creating a store instance.`) assert(typeof Promise !== 'undefined', `vuex requires a Promise polyfill in this browser.`) + assert(this instanceof Store, `Store must be called with the new operator.`) const { plugins = [], diff --git a/test/unit/store.spec.js b/test/unit/store.spec.js index 416f5c56c..71bdc2921 100644 --- a/test/unit/store.spec.js +++ b/test/unit/store.spec.js @@ -334,6 +334,12 @@ describe('Store', () => { }) }) + it('asserts the call with the new operator', () => { + expect(() => { + Vuex.Store({}) + }).toThrowError(/Store must be called with the new operator/) + }) + it('should accept state as function', () => { const store = new Vuex.Store({ state: () => ({