restructured code/added tests

This commit is contained in:
Philipp Czora
2018-07-19 17:37:20 +02:00
parent 1d3d1bb41e
commit 9ab231477c
2 changed files with 61 additions and 34 deletions

View File

@@ -30,7 +30,9 @@ import {
addUserFailure,
updateUserFailure,
deleteUserSuccess,
failedToFetchUsers
failedToFetchUsers,
requestUser,
fetchUserFailure
} from "./users";
import reducer from "./users";
@@ -404,4 +406,17 @@ describe("users reducer", () => {
expect(newState.users.loading).toBeFalsy();
expect(newState.users.error).toEqual(new Error("kaputt kaputt"));
});
it("should update state according to FETCH_USER action", () => {
const newState = reducer({}, requestUser("zaphod"));
expect(newState.usersByNames["zaphod"].loading).toBeTruthy();
});
it("should uppdate state according to FETCH_USER_FAILURE action", () => {
const newState = reducer(
{},
fetchUserFailure(userFord, new Error("kaputt!"))
);
expect(newState.usersByNames["ford"].error).toBeTruthy;
});
});