Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import { ADD_TO_CART, REMOVE_FROM_CART } from "./actionTypes";
- import rootReducer from './rootReducer';
- let action;
- let state;
- it("is a function", function () {
- expect(typeof rootReducer).toEqual("function");
- });
- describe("ADD_TO_CART", function () {
- beforeEach(function () {
- action = {
- type: ADD_TO_CART,
- id: 1234
- }
- state = { cart: [] }
- });
- it("should add a product id to state.cart", function () {
- expect(rootReducer(state, action)).toEqual({cart: [1234]})
- });
- it("should be a pure function", function () {
- rootReducer(state, action)
- expect(state).toEqual({ cart: [] });
- });
- });
- describe("REMOVE_FROM_CARt", function () {
- beforeEach(function () {
- action = {
- type: REMOVE_FROM_CART,
- id: 1234
- }
- state = {cart: [1234, 4321]}
- });
- it("should delete a product id from state.cart", function () {
- expect(rootReducer(state, action)).toEqual({ cart: [4321]});
- })
- it("should delete only one product id from state.cart", function () {
- state.cart.push(1234)
- expect(rootReducer(state, action)).toEqual({ cart: [4321, 1234]});
- })
- it("should be a pure function", function () {
- rootReducer(state, action)
- expect(state).toEqual({cart: [1234, 4321]});
- });
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement