fixed code smells and added some more tests

This commit is contained in:
Sebastian Sdorra
2018-07-30 15:51:45 +02:00
parent b825de3058
commit cba3fc38e6
6 changed files with 45 additions and 9 deletions

View File

@@ -10,6 +10,12 @@ describe("failure reducer", () => {
expect(newState["FETCH_ITEMS"]).toBe(err);
});
it("should do nothing for unknown action types", () => {
const state = {};
const newState = reducer(state, { type: "UNKNOWN" });
expect(newState).toBe(state);
});
it("should set the error for FETCH_ITEMS, if payload has multiple values", () => {
const newState = reducer(
{},
@@ -52,6 +58,18 @@ describe("failure reducer", () => {
expect(newState["FETCH_ITEMS"]).toBeFalsy();
});
it("should reset FETCH_ITEMS after FETCH_ITEMS_RESET, but should not affect others", () => {
const newState = reducer(
{
FETCH_ITEMS: err,
FETCH_USERS: err
},
{ type: "FETCH_ITEMS_RESET" }
);
expect(newState["FETCH_ITEMS"]).toBeFalsy();
expect(newState["FETCH_USERS"]).toBe(err);
});
it("should set the error for a single item of FETCH_ITEM", () => {
const newState = reducer(
{},
@@ -59,6 +77,14 @@ describe("failure reducer", () => {
);
expect(newState["FETCH_ITEM/42"]).toBe(err);
});
it("should reset error for a single item of FETCH_ITEM", () => {
const newState = reducer(
{ "FETCH_ITEM/42": err },
{ type: "FETCH_ITEM_SUCCESS", payload: err, itemId: 42 }
);
expect(newState["FETCH_ITEM/42"]).toBeUndefined();
});
});
describe("failure selector", () => {