Advertisement
Guest User

Untitled

a guest
Aug 20th, 2019
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.23 KB | None | 0 0
  1. import { ADD_TO_CART, REMOVE_FROM_CART } from "./actionTypes";
  2. import rootReducer from './rootReducer';
  3.  
  4. let action;
  5. let state;
  6.  
  7. it("is a function", function () {
  8. expect(typeof rootReducer).toEqual("function");
  9. });
  10.  
  11. describe("ADD_TO_CART", function () {
  12. beforeEach(function () {
  13. action = {
  14. type: ADD_TO_CART,
  15. id: 1234
  16. }
  17. state = { cart: [] }
  18. });
  19.  
  20. it("should add a product id to state.cart", function () {
  21. expect(rootReducer(state, action)).toEqual({cart: [1234]})
  22. });
  23.  
  24. it("should be a pure function", function () {
  25. rootReducer(state, action)
  26. expect(state).toEqual({ cart: [] });
  27. });
  28. });
  29.  
  30. describe("REMOVE_FROM_CARt", function () {
  31. beforeEach(function () {
  32. action = {
  33. type: REMOVE_FROM_CART,
  34. id: 1234
  35. }
  36. state = {cart: [1234, 4321]}
  37. });
  38.  
  39. it("should delete a product id from state.cart", function () {
  40. expect(rootReducer(state, action)).toEqual({ cart: [4321]});
  41. })
  42.  
  43. it("should delete only one product id from state.cart", function () {
  44. state.cart.push(1234)
  45. expect(rootReducer(state, action)).toEqual({ cart: [4321, 1234]});
  46. })
  47.  
  48. it("should be a pure function", function () {
  49. rootReducer(state, action)
  50. expect(state).toEqual({cart: [1234, 4321]});
  51. });
  52. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement