Skip to content

Instantly share code, notes, and snippets.

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 kanerogers/a3e22a01b2844cf1034cf47d073e889e to your computer and use it in GitHub Desktop.
Save kanerogers/a3e22a01b2844cf1034cf47d073e889e to your computer and use it in GitHub Desktop.
Test TodosComponent
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