835
ReactNoop.flush();
836
expect(ops).toEqual(['Foo', 'Bar', 'Baz', 'Bar', 'Baz']);
837
});
838
+
839
+ it('can call sCU while resuming a partly mounted component', () => {
840
+ var ops = [];
841
+
842
+ class Bar extends React.Component {
843
+ state = { y: 'A' };
844
+ shouldComponentUpdate(newProps, newState) {
845
+ return this.props.x !== newProps.x ||
846
+ this.state.y !== newState.y;
847
+ }
848
+ render() {
849
+ ops.push('Bar:' + this.props.x);
850
+ return <span prop={'' + (this.props.x === this.state.y)} />;
851
+ }
852
+ }
853
+
854
+ function Foo(props) {
855
+ ops.push('Foo');
856
+ return [
857
+ <Bar key="a" x="A" />,
858
+ <Bar key="b" x="B" />,
859
+ <Bar key="c" x="C" />,
860
+ ];
861
+ }
862
+
863
+ ReactNoop.render(<Foo />);
864
+ ReactNoop.flushDeferredPri(30);
865
+ expect(ops).toEqual(['Foo', 'Bar:A', 'Bar:B']);
866
+
867
+ ops = [];
868
+
869
+ ReactNoop.render(<Foo />);
870
+ ReactNoop.flushDeferredPri(40);
871
+ expect(ops).toEqual(['Foo', 'Bar:B', 'Bar:C']);
872
+ });
873
+
874
+ it('gets new props when setting state on a partly updated component', () => {
875
+ var ops = [];
876
+ var instances = [];
877
+
878
+ class Bar extends React.Component {
879
+ state = { y: 'A' };
880
+ constructor() {
881
+ super();
882
+ instances.push(this);
883
+ }
884
+ performAction() {
885
+ this.setState({
886
+ y: 'B',
887
+ });
888
+ }
889
+ render() {
890
+ ops.push('Bar:' + this.props.x + '-' + this.props.step);
891
+ return <span prop={'' + (this.props.x === this.state.y)} />;
892
+ }
893
+ }
894
+
895
+ function Baz() {
896
+ // This component is used as a sibling to Foo so that we can fully
897
+ // complete Foo, without committing.
898
+ ops.push('Baz');
899
+ return <div />;
900
+ }
901
+
902
+ function Foo(props) {
903
+ ops.push('Foo');
904
+ return [
905
+ <Bar key="a" x="A" step={props.step} />,
906
+ <Bar key="b" x="B" step={props.step} />,
907
+ ];
908
+ }
909
+
910
+ ReactNoop.render(<div><Foo step={0} /><Baz /><Baz /></div>);
911
+ ReactNoop.flush();
912
+
913
+ ops = [];
914
+
915
+ // Flush part way through with new props, fully completing the first Bar.
916
+ // However, it doesn't commit yet.
917
+ ReactNoop.render(<div><Foo step={1} /><Baz /><Baz /></div>);
918
+ ReactNoop.flushDeferredPri(45);
919
+ expect(ops).toEqual(['Foo', 'Bar:A-1', 'Bar:B-1', 'Baz']);
920
+
921
+ // Make an update to the same Bar.
922
+ instances[0].performAction();
923
+
924
+ ops = [];
925
+
926
+ ReactNoop.flush();
927
+ expect(ops).toEqual(['Bar:A-1', 'Baz', 'Baz']);
928
+ });
929
+
930
});