Skip to content

Instantly share code, notes, and snippets.

@lomse
Created October 20, 2018 18:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lomse/a21a0c6ccf0c5003efd57b5171ca80c4 to your computer and use it in GitHub Desktop.
Save lomse/a21a0c6ccf0c5003efd57b5171ca80c4 to your computer and use it in GitHub Desktop.
helper.test.js file
import { addTodo } from './helper'
describe('addTodo', () => {
it('should add todo to the list', () => {
const startTodos = [
{ id: 1, name: 'one', isComplete: false },
{ id: 2, name: 'two', isComplete: false }
]
const newTodo = { id: 3, name: 'three', isComplete: false }
const expected = [
{ id: 3, name: 'three', isComplete: false },
{ id: 1, name: 'one', isComplete: false },
{ id: 2, name: 'two', isComplete: false }
]
const result = addTodo(startTodos, newTodo)
expect(result).toEqual(expected)
})
it('should not mutate the existing todo array', () => {
const startTodos = [
{ id: 1, name: 'one', isComplete: false },
{ id: 2, name: 'two', isComplete: false }
]
const newTodo = { id: 3, name: 'three', isComplete: false }
const result = addTodo(startTodos, newTodo)
expect(result).not.toBe(startTodos)
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment