Guest User

Untitled

a guest
Sep 24th, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.67 KB | None | 0 0
  1. import calculatorReducer from '../store/reducers/calculateReducer';
  2. import * as types from '../store/types';
  3.  
  4. describe('Calculator Reducer', () => {
  5.  
  6.  
  7. it ('should return the initial state', () => {
  8. const initialState = {
  9. expression: '',
  10. total: 0
  11. }
  12.  
  13. expect(calculatorReducer(undefined, {})).toEqual(initialState)
  14. })
  15.  
  16.  
  17.  
  18. it ('should handle SET_EXPRESSION', () => {
  19. const expected = {
  20. expression: '5*5',
  21. total: 25
  22. }
  23.  
  24. const action = {
  25. type: types.SET_EXPRESSION,
  26. payload: '5*5'
  27. }
  28.  
  29. expect(calculatorReducer(undefined, action)).toEqual(expected)
  30. })
  31.  
  32.  
  33.  
  34.  
  35. it ('should handle CLEAR_EXPRESSION', () => {
  36. const expected = {
  37. expression: '',
  38. total: 0
  39. }
  40.  
  41. const initialState = {
  42. expression: '4*5',
  43. total: 25
  44. }
  45.  
  46. const action = {
  47. type: types.CLEAR_EXPRESSION,
  48. payload: ''
  49. }
  50.  
  51. expect(calculatorReducer(initialState, action)).toEqual(expected)
  52. })
  53.  
  54.  
  55.  
  56.  
  57. it ('should handle DELETE_LAST_EXPRESSION_ENTRY', () => {
  58. const expected = {
  59. expression: '4*5*',
  60. total: 20
  61. }
  62.  
  63. const initialState = {
  64. expression: '4*5*6',
  65. total: 120
  66. }
  67.  
  68. const action = {
  69. type: types.DELETE_LAST_EXPRESSION_ENTRY,
  70. payload: ''
  71. }
  72.  
  73. expect(calculatorReducer(initialState, action)).toEqual(expected)
  74. })
  75.  
  76.  
  77. it ('should handle EVALUATE_EXPRESSION', () => {
  78. const expected = {
  79. expression: '',
  80. total: 120
  81. }
  82.  
  83. const initialState = {
  84. expression: '4*5*6',
  85. total: 120
  86. }
  87.  
  88. const action = {
  89. type: types.EVALUATE_EXPRESSION,
  90. payload: ''
  91. }
  92.  
  93. expect(calculatorReducer(initialState, action)).toEqual(expected)
  94. })
  95.  
  96. })
Add Comment
Please, Sign In to add comment