Skip to content

Instantly share code, notes, and snippets.

@viceversus
Created January 30, 2016 01:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save viceversus/76edbaf18dee7b26a971 to your computer and use it in GitHub Desktop.
Save viceversus/76edbaf18dee7b26a971 to your computer and use it in GitHub Desktop.
List Wrapper Spec
import React from 'react';
import "babel-polyfill";
import listWrapper from 'list_wrapper';
import { shallow } from 'enzyme';
describe('ListWrapper', function () {
var wrapper, ListComponent, MockListComponent, instance, set;
beforeEach(function () {
MockListComponent = React.createClass({
render: function () {
return (<div>Fake List</div>);
},
});
set = new Set();
WrapperComponent = listWrapper(MockListComponent);
wrapper = shallow(<ListComponent />);
instance = wrapper.instance();
});
it('renders the List Component as the root element', function () {
expect(wrapper.first().is(MockListComponent)).toBeTruthy();
});
describe('handleOnSelect', function () {
describe('when not already selected', function () {
it('adds the key to the selection set', function () {
instance.handleOnSelect('1234');
expect(instance.state.selection.has('1234')).toBeTruthy();
});
});
describe('when already selected', function () {
beforeEach(function () {
instance.setState({selection: new Set(['2314'])});
});
it('removes the selection from the set', function () {
instance.handleOnSelect('2314');
expect(instance.state.selection.has('1234')).toBeFalsy();
});
});
});
});
@trevlar
Copy link

trevlar commented Nov 21, 2017

It appears that wrong component is being passed to the shallow function in this test.
Instead of passing ListComponent into shallow it needs to pass WrapperComponent.

    WrapperComponent = listWrapper(MockListComponent);
    wrapper = shallow(<WrapperComponent />);

In fact you don't even need the ListComponent variable see the changes in my fork.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment