Test ability to abort work
Sebastian Markbage committed
Jun 11, 2016 at 20:32 UTC
61fe5e11dc44b73f5ab9b11a3670e4cab761c64f
1 file changed
+50
src/renderers/shared/fiber/__tests__/ReactIncremental-test.js
+50
@@ -115,4 +115,54 @@ describe('ReactIncremental', function() {
115
116
});
117
118
+ it('can cancel partially rendered work and restart', function() {
119
+
120
+ var ops = [];
121
+
122
+ function Bar(props) {
123
+ ops.push('Bar');
124
+ return <div>{props.children}</div>;
125
+ }
126
+
127
+ function Foo(props) {
128
+ ops.push('Foo');
129
+ return (
130
+ <div>
131
+ <Bar>{props.text}</Bar>
132
+ <Bar>{props.text}</Bar>
133
+ </div>
134
+ );
135
+ }
136
+
137
+ // Init
138
+ ReactNoop.render(<Foo text="foo" />);
139
+ ReactNoop.flush();
140
+
141
+ ops = [];
142
+
143
+ ReactNoop.render(<Foo text="bar" />);
144
+ // Flush part of the work
145
+ ReactNoop.flushLowPri(20);
146
+
147
+ expect(ops).toEqual(['Foo', 'Bar']);
148
+
149
+ ops = [];
150
+
151
+ // This will abort the previous work and restart
152
+ ReactNoop.render(<Foo text="baz" />);
153
+
154
+ // Flush part of the new work
155
+ ReactNoop.flushLowPri(20);
156
+
157
+ expect(ops).toEqual(['Foo', 'Bar']);
158
+
159
+ // Flush the rest of the work which now includes the low priority
160
+ ReactNoop.flush(20);
161
+
162
+ expect(ops).toEqual(['Foo', 'Bar', 'Bar']);
163
+
164
+ // TODO: Test the ability for a subtree to resume if it has lower priority.
165
+
166
+ });
167
+
168
});