Created
August 10, 2018 21:25
-
-
Save Gbaja/00966b49ef6d0bdc7239fbaad9c87910 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import deepFreeze from "deep-freeze"; | |
//importing deep-freeze, an npm module which helps to make sure I am not mutating state as that is the rule for a reducer | |
describe("Alert reducer", () => { | |
it("Adds an error", () => { | |
const initialState = { | |
type:"", | |
message:"" | |
}; | |
const action = { | |
type: ADD_ERROR, | |
payload: { type: "error", message: "oops, something went wrong" } | |
}; | |
//declaring my action variable to let redux know what action to dispatch | |
deepFreeze(initialState); | |
//calling the deepFreeze function on the initialState to make its value “frozen” and ensure it is not been mutated. | |
const updatedState = alertReducer(initialState, action); | |
//updateState variable is the returned value of calling the alertReducer function declared earlier | |
const expectedState = { | |
type: "error", | |
message: "oops, something went wrong" | |
}; | |
expect(updatedState).toEqual(expectedState); | |
//comparing the values of the updatedState with that of the expected state | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment