Skip to content

Commit e0504cc

Browse files
termosaktsn
authored andcommitted
[improvement] Add assertion to verify using of new (vuejs#698)
* [improvement] Add assertion to verify using of new I see people are asking about this problem so often, that I feel it worth to put this assertion into the code to save some time for those developers. * [fix] Revert dist folder
1 parent cc5fc79 commit e0504cc

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

src/store.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ export class Store {
99
constructor (options = {}) {
1010
assert(Vue, `must call Vue.use(Vuex) before creating a store instance.`)
1111
assert(typeof Promise !== 'undefined', `vuex requires a Promise polyfill in this browser.`)
12+
assert(this instanceof Store, `Store must be called with the new operator.`)
1213

1314
const {
1415
plugins = [],

test/unit/store.spec.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,12 @@ describe('Store', () => {
334334
})
335335
})
336336

337+
it('asserts the call with the new operator', () => {
338+
expect(() => {
339+
Vuex.Store({})
340+
}).toThrowError(/Store must be called with the new operator/)
341+
})
342+
337343
it('should accept state as function', () => {
338344
const store = new Vuex.Store({
339345
state: () => ({

0 commit comments

Comments
 (0)