Skip to content

Instantly share code, notes, and snippets.

@kevinsalter
Created May 27, 2016 16:45
Show Gist options
  • Save kevinsalter/f1bdd6adbd8dc814c67e3426147359cd to your computer and use it in GitHub Desktop.
Save kevinsalter/f1bdd6adbd8dc814c67e3426147359cd to your computer and use it in GitHub Desktop.
<MainView /> unit tests
import React from 'react';
import {shallow} from 'enzyme';
import {assert} from 'chai';
import {spy} from 'sinon';
import MainView from '../src/main-view.js';
import {Users} from '../fixtures/users.js';
describe('<MainView />', () => {
const MAIN_VIEW_PROPS = {
ghUsers: Users,
refreshUserList: spy()
};
it('should contain a list of users', () => {
const wrapper = shallow(<MainView {...MAIN_VIEW_PROPS} />);
const listWrapper = wrapper.find('ul');
assert.equal(listWrapper.length, 1);
assert.ok(listWrapper.children());
});
it('should call the refreshUserList() method when button is clicked', () => {
const wrapper = shallow(<MainView {...MAIN_VIEW_PROPS} />);
const refreshUserListButton = wrapper.find('button');
refreshUserListButton.simulate('click');
assert.ok(MAIN_VIEW_PROPS.refreshUserList.calledOnce);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment