th3mon
10/29/2017 - 12:35 AM

JS Bin// source http://jsbin.com/muqigog

JS Bin// source http://jsbin.com/muqigog

console.clear()

const todos = (state = [], action) => {
  switch (action.type) {
    case 'ADD_TODO':
      return [
        ...state,
        {
          id: action.id,
          text: action.text,
          completed: false
        }
      ]
      
      default:
        return state
  }
}

const testAddTodo = () => {
  const stateBefore = [];
  const action = {
    type: 'ADD_TODO',
    id: 0,
    text: 'Learn Redux'
  }
  const stateAfter = [{
    id: 0,
    text: 'Learn Redux',
    completed: false
  }]
  
  deepFreeze(stateBefore)
  deepFreeze(stateBefore)
  
  expect(
    todos(stateBefore, action)
  ).toEqual(stateAfter)
}

testAddTodo()

console.log('All test passed.')
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>JS Bin</title>
</head>
<body>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/expect/1.20.2/expect.min.js"></script>
  <script src="https://wzrd.in/standalone/deep-freeze@latest"></script>
<script id="jsbin-javascript">
console.clear()

const todos = (state = [], action) => {
  switch (action.type) {
    case 'ADD_TODO':
      return [
        ...state,
        {
          id: action.id,
          text: action.text,
          completed: false
        }
      ]
      
      default:
        return state
  }
}

const testAddTodo = () => {
  const stateBefore = [];
  const action = {
    type: 'ADD_TODO',
    id: 0,
    text: 'Learn Redux'
  }
  const stateAfter = [{
    id: 0,
    text: 'Learn Redux',
    completed: false
  }]
  
  deepFreeze(stateBefore)
  deepFreeze(stateBefore)
  
  expect(
    todos(stateBefore, action)
  ).toEqual(stateAfter)
}

testAddTodo()

console.log('All test passed.')
</script>



<script id="jsbin-source-javascript" type="text/javascript">console.clear()

const todos = (state = [], action) => {
  switch (action.type) {
    case 'ADD_TODO':
      return [
        ...state,
        {
          id: action.id,
          text: action.text,
          completed: false
        }
      ]
      
      default:
        return state
  }
}

const testAddTodo = () => {
  const stateBefore = [];
  const action = {
    type: 'ADD_TODO',
    id: 0,
    text: 'Learn Redux'
  }
  const stateAfter = [{
    id: 0,
    text: 'Learn Redux',
    completed: false
  }]
  
  deepFreeze(stateBefore)
  deepFreeze(stateBefore)
  
  expect(
    todos(stateBefore, action)
  ).toEqual(stateAfter)
}

testAddTodo()

console.log('All test passed.')</script></body>
</html>