Created
May 30, 2016 10:25
-
-
Save kanerogers/a3e22a01b2844cf1034cf47d073e889e to your computer and use it in GitHub Desktop.
Test TodosComponent
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react'; | |
import { expect } from 'chai'; | |
import { shallow } from 'enzyme'; | |
import sinon from 'sinon'; | |
describe('<Todos />', () => { | |
it('renders the <TodosComponent /> correctly', () => { | |
const TEST_ONPRESS = sinon.spy(); | |
const TEST_TODOS = [ | |
{ id: 0, text: 'Learn Redux' }, | |
{ id: 1, text: 'Learn TDD' }, | |
]; | |
const wrapper = shallow(<TodosComponent todos={TEST_TODOS} onPress={TEST_ONPRESS} />); | |
// Assert it rendered our list of todos. | |
expect(wrapper.children().length).to.equal(TEST_TODOS.length); | |
// Assert our onPress function was passed along correctly. | |
wrapper.children().forEach(t => t.simulate('press'); // Press each todo. | |
expect(sinon.calledWith(TEST_TODOS[0].id)).to.equal(true); // Make sure the correct params were triggered. | |
expect(sinon.calledWith(TEST_TODOS[1].id)).to.equal(true); // Make sure the correct params were triggered. | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment