Created
January 30, 2016 01:10
-
-
Save viceversus/76edbaf18dee7b26a971 to your computer and use it in GitHub Desktop.
List Wrapper Spec
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 "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(); | |
}); | |
}); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
In fact you don't even need the ListComponent variable see the changes in my fork.