Skip to content

Commit

Permalink
Add todolist tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jontewks committed Mar 3, 2016
1 parent 1e348a7 commit b955925
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions examples/todos/test/components/TodoList.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import React from 'react'
import TestUtils from 'react-addons-test-utils'
import expect from 'expect'

import TodoList from '../../components/TodoList'
import Todo from '../../components/Todo'

function setup(propsOveride) {
const renderer = TestUtils.createRenderer()
renderer.render(
<TodoList
todos={[{
id: 1,
completed: false,
text: 'Request a raise',
}]}
onTodoClick={() => {}}
{...propsOveride}
/>
)
return renderer.getRenderOutput()
}

describe('Components', () => {
describe('TodoList', () => {
it('Renders a list of todo items', () => {
const output = setup()
expect(output.type).toBe('ul')

const children = output.props.children
expect(children[0].type).toBe(Todo)
})

it('Passes onTodoClick to each child', () => {
let hasFired = false
const output = setup({
onTodoClick() {
hasFired = true
},
})

const children = output.props.children
children[0].props.onClick()
expect(hasFired).toBe(true)
})
})
})

0 comments on commit b955925

Please sign in to comment.