Skip to content

Commit

Permalink
fix(connect): Fix a bug where props with falsy values would not be se…
Browse files Browse the repository at this point in the history
…nt to the wrapped component
  • Loading branch information
BenoitAverty committed Aug 16, 2016
1 parent 47db56b commit 549bb8d
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,8 @@ src/
test/
.nyc_output/
coverage/
examples/
*.webpack.config.js
.babelrc
.eslintrc
.gitignore
2 changes: 1 addition & 1 deletion src/connect.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const connect = (propsToPass, callbackName) => (Component) => {
}

propSubscritpion(prop) {
if (prop.value) {
if (prop.value !== undefined) {
this.setState({
[prop.name]: prop.value,
});
Expand Down
17 changes: 17 additions & 0 deletions test/cycleReactDriver.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,23 @@ describe('Cycle React Driver', () => {
expect(renderMock.getWrapper().find(Dummy)).to.not.have.prop('prop');
});

it('Should render a prop from the driver if its value is falsy but defined', () => {
const ConnectedDummy = connect()(Dummy);
const cycleReactDriver = makeCycleReactDriver(<ConnectedDummy />, '#app');
const prop = new Rx.Subject();

cycleReactDriver(prop);
prop.next({ name: 'prop1', value: 0 });
prop.next({ name: 'prop2', value: null });
prop.next({ name: 'prop3', value: '' });
prop.next({ name: 'prop4', value: false });

expect(renderMock.getWrapper().find(Dummy)).to.have.prop('prop1', 0);
expect(renderMock.getWrapper().find(Dummy)).to.have.prop('prop2', null);
expect(renderMock.getWrapper().find(Dummy)).to.have.prop('prop3', '');
expect(renderMock.getWrapper().find(Dummy)).to.have.prop('prop4', false);
});

it('Should only render props specified in connect', () => {
const ConnectedDummy = connect(['filteredIn'])(Dummy);
const cycleReactDriver = makeCycleReactDriver(<ConnectedDummy />, '#app');
Expand Down

0 comments on commit 549bb8d

Please sign in to comment.