Skip to content

Commit

Permalink
Add failing test for reduxjs#86
Browse files Browse the repository at this point in the history
  • Loading branch information
esamattis committed Sep 9, 2015
1 parent c2f7166 commit 683ba87
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions test/components/connect.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1148,5 +1148,51 @@ describe('React', () => {
wrapper.setState({ value: 1 });
expect(target.props.statefulValue).toEqual(1);
});

it('should not pass stale data to mapState', () => {
const store = createStore(stringBuilder);
store.dispatch({ type: 'APPEND', body: 'initial'});
let childMapStateExecuted = false;

@connect(state => ({ string: state }) )
class Container extends Component {

emitChange() {
store.dispatch({ type: 'APPEND', body: 'changed'});
}

render() {
return (
<div>
<button ref="button" onClick={this.emitChange.bind(this)}>change</button>
<ChildContainer parentString={this.props.string} />
</div>
);
}
}

@connect((state, parentProps) => {
childMapStateExecuted = true;
// The state from parent props should always be consistent with the current state
expect(state).toEqual(parentProps.parentString);
return {};
})
class ChildContainer extends Component {
render() {
return <Passthrough {...this.props}/>;
}
}

const tree = TestUtils.renderIntoDocument(
<ProviderMock store={store}>
<Container />
</ProviderMock>
);

const container = TestUtils.findRenderedComponentWithType(tree, Container);
const node = React.findDOMNode(container.getWrappedInstance().refs.button);
TestUtils.Simulate.click(node);
expect(childMapStateExecuted).toBe(true);
});
});
});

0 comments on commit 683ba87

Please sign in to comment.