Skip to content

Commit

Permalink
test(#13): mutations should implement resetState in order for correct…
Browse files Browse the repository at this point in the history
…ly "reset" the emptyState
  • Loading branch information
andrewbeng89 committed Jun 22, 2020
1 parent ca08eac commit c8edfe8
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
7 changes: 6 additions & 1 deletion tests/store-non-namespaced/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const debug = process.env.NODE_ENV !== "production";
interface State {
list: Array<any>;
shadow: Array<any>;
resetList?: Array<any>;
}

interface Payload {
Expand All @@ -29,7 +30,8 @@ interface Context {

const state: State = {
list: [],
shadow: []
shadow: [],
resetList: undefined
};

const getters = {
Expand All @@ -53,6 +55,9 @@ const mutations = {
emptyState: (state: State) => {
state.list = [];
},
resetState: (state: State) => {
state.resetList = [...state.list];
},
addItem: (state: State, { item }: Payload) => {
state.list = [...state.list, item];
},
Expand Down
9 changes: 7 additions & 2 deletions tests/store/modules/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ const debug = process.env.NODE_ENV !== "production";

const state = {
list: [],
shadow: []
shadow: [],
resetList: undefined
};

const getters = {
Expand Down Expand Up @@ -41,7 +42,11 @@ const actions = {

export const mutations = {
emptyState: (state: any) => {
state.list = [];
const list = [...(state.resetList || [])];
state.list = list;
},
resetState: (state: any) => {
state.resetList = [...state.list];
},
addItem: (state: any, { item }: { item: any }) => {
state.list = [...state.list, item];
Expand Down

0 comments on commit c8edfe8

Please sign in to comment.