fix: prevent issue in store with existing values in array

This commit is contained in:
Géry Debongnie
2019-04-09 09:40:18 +02:00
parent bf4cbaea33
commit 7ea782bd60
2 changed files with 22 additions and 3 deletions
+1 -1
View File
@@ -204,7 +204,7 @@ function _magifyArray({ raw, key, parent, magic, onDirty }) {
}); });
} }
}); });
raw.forEach(([value, index]) => { raw.forEach((value, index) => {
let prop = magify({ let prop = magify({
raw: value, raw: value,
key: index, key: index,
+21 -2
View File
@@ -104,6 +104,22 @@ describe("advanced state properties", () => {
expect(store.state).not.toBe(state); expect(store.state).not.toBe(state);
}); });
test("can push an item in a list with an existing item", async () => {
const mutations = {
addRochefort(state) {
state.rocheforts.push({ taste: 87 });
}
};
const store = new Store({
state: { rocheforts: [{ taste: 84 }] },
mutations
});
const state = store.state;
store.commit("addRochefort");
expect(store.state.rocheforts).toEqual([{ taste: 84 }, { taste: 87 }]);
expect(store.state).toBe(state);
});
test("state is reference equal after pushing in a list", async () => { test("state is reference equal after pushing in a list", async () => {
const mutations = { const mutations = {
addRochefort(state) { addRochefort(state) {
@@ -538,7 +554,7 @@ describe("connecting a component to store", () => {
]); ]);
}); });
test.skip("connect receives ownprops as second argument", async () => { test("connect receives ownprops as second argument", async () => {
const state = { todos: [{ id: 1, text: "jupiler" }] }; const state = { todos: [{ id: 1, text: "jupiler" }] };
let nextId = 2; let nextId = 2;
const mutations = { const mutations = {
@@ -565,7 +581,10 @@ describe("connecting a component to store", () => {
widgets = { ConnectedTodo }; widgets = { ConnectedTodo };
} }
const ConnectedTodoList = connect(state => state)(TodoList); function mapStateToProps(state) {
return { todos: state.todos };
}
const ConnectedTodoList = connect(mapStateToProps)(TodoList);
(<any>env).store = store; (<any>env).store = store;
const app = new ConnectedTodoList(env); const app = new ConnectedTodoList(env);