Advertisement
Guest User

Untitled

a guest
Oct 20th, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function counter(state = 0){
  2.   if(action.type === "INCREMENT"){
  3.     return state +1
  4.   } else if(action.type === "DECREMENT"){
  5.     return state - 1
  6.   } else {
  7.     return state
  8.   }
  9. }
  10.  
  11. expect(
  12. counter(0, {type: "INCREMENT"})
  13. ).toEqual(1)
  14.  
  15. expect(
  16. counter(1, {type: "INCREMENT"})
  17. ).toEqual(2)
  18.  
  19. expect(
  20.   counter(2, {type: "DECREMENT"})
  21. ).toEqual(1)
  22.  
  23. expect(
  24.   counter(2, {type: "DECREMENT"})
  25. ).toEqual(0)
  26.  
  27. expect(
  28.   counter(undefined, {})
  29. ).toEqual(0)
  30.  
  31. console.log('test passed')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement