From 683ba87626482381bc5a6c000139c1274b8ac0e8 Mon Sep 17 00:00:00 2001 From: Esa-Matti Suuronen Date: Wed, 9 Sep 2015 10:14:16 +0000 Subject: [PATCH] Add failing test for #86 --- test/components/connect.spec.js | 46 +++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/test/components/connect.spec.js b/test/components/connect.spec.js index 8af12bb2b..614ae4743 100644 --- a/test/components/connect.spec.js +++ b/test/components/connect.spec.js @@ -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 ( +
+ + +
+ ); + } + } + + @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 ; + } + } + + const tree = TestUtils.renderIntoDocument( + + + + ); + + const container = TestUtils.findRenderedComponentWithType(tree, Container); + const node = React.findDOMNode(container.getWrappedInstance().refs.button); + TestUtils.Simulate.click(node); + expect(childMapStateExecuted).toBe(true); + }); }); });