imp: prevent store state change outside a mutation

This commit is contained in:
Géry Debongnie
2019-04-12 12:05:06 +02:00
parent 03511ce9ea
commit f1cc32de8f
2 changed files with 23 additions and 6 deletions
+13
View File
@@ -41,6 +41,19 @@ describe("basic use", () => {
expect(store.state.n).toBe(15);
});
test("modifying state outside of mutations trigger error", () => {
const state = { n: 1 };
const actions = {
inc({ state }) {
state.n++;
}
};
const store = new Store({ state, mutations: {}, actions });
expect(() => store.dispatch("inc")).toThrow();
expect(() => (store.state.n = 15)).toThrow();
});
test("can dispatch an action in an action", () => {
const state = { n: 1 };
const mutations = {