Skip to content

Commit 683ba87

Browse files
committed
Add failing test for reduxjs#86
1 parent c2f7166 commit 683ba87

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

test/components/connect.spec.js

+46
Original file line numberDiff line numberDiff line change
@@ -1148,5 +1148,51 @@ describe('React', () => {
11481148
wrapper.setState({ value: 1 });
11491149
expect(target.props.statefulValue).toEqual(1);
11501150
});
1151+
1152+
it('should not pass stale data to mapState', () => {
1153+
const store = createStore(stringBuilder);
1154+
store.dispatch({ type: 'APPEND', body: 'initial'});
1155+
let childMapStateExecuted = false;
1156+
1157+
@connect(state => ({ string: state }) )
1158+
class Container extends Component {
1159+
1160+
emitChange() {
1161+
store.dispatch({ type: 'APPEND', body: 'changed'});
1162+
}
1163+
1164+
render() {
1165+
return (
1166+
<div>
1167+
<button ref="button" onClick={this.emitChange.bind(this)}>change</button>
1168+
<ChildContainer parentString={this.props.string} />
1169+
</div>
1170+
);
1171+
}
1172+
}
1173+
1174+
@connect((state, parentProps) => {
1175+
childMapStateExecuted = true;
1176+
// The state from parent props should always be consistent with the current state
1177+
expect(state).toEqual(parentProps.parentString);
1178+
return {};
1179+
})
1180+
class ChildContainer extends Component {
1181+
render() {
1182+
return <Passthrough {...this.props}/>;
1183+
}
1184+
}
1185+
1186+
const tree = TestUtils.renderIntoDocument(
1187+
<ProviderMock store={store}>
1188+
<Container />
1189+
</ProviderMock>
1190+
);
1191+
1192+
const container = TestUtils.findRenderedComponentWithType(tree, Container);
1193+
const node = React.findDOMNode(container.getWrappedInstance().refs.button);
1194+
TestUtils.Simulate.click(node);
1195+
expect(childMapStateExecuted).toBe(true);
1196+
});
11511197
});
11521198
});

0 commit comments

Comments
 (0)