@samitouri / QOS-React / commits / 9166cf9b8d

Add test for duplicate events with nested dispatch

Mateusz Burzyński committed Aug 9, 2017 at 16:30 UTC 9166cf9b8d21b51098f5bf44c09925657ca93929
2 files changed +51
scripts/fiber/tests-passing.txt
+1
@@ -759,6 +759,7 @@ src/renderers/dom/shared/__tests__/ReactDOM-test.js
759 * throws in render() if the update callback is not a function
760 * preserves focus
761 * calls focus() on autoFocus elements after they have been mounted to the DOM
762 +* shouldn't fire duplicate event handler while handling other nested dispatch
763
764 src/renderers/dom/shared/__tests__/ReactDOMComponent-test.js
765 * should handle className
src/renderers/dom/shared/__tests__/ReactDOM-test.js
+50
@@ -289,4 +289,54 @@ describe('ReactDOM', () => {
289 HTMLElement.prototype.focus = originalFocus;
290 }
291 });
292 +
293 + it("shouldn't fire duplicate event handler while handling other nested dispatch", () => {
294 + const actual = [];
295 +
296 + function click(node) {
297 + var fakeNativeEvent = function() {};
298 + fakeNativeEvent.target = node;
299 + fakeNativeEvent.path = [node, container];
300 + ReactTestUtils.simulateNativeEventOnNode(
301 + 'topClick',
302 + node,
303 + fakeNativeEvent,
304 + );
305 + }
306 +
307 + class Wrapper extends React.Component {
308 + componentDidMount() {
309 + click(this.ref1);
310 + }
311 +
312 + render() {
313 + return (
314 + <div>
315 + <div
316 + onClick={() => {
317 + actual.push('1st node clicked');
318 + click(this.ref2);
319 + }}
320 + ref={ref => (this.ref1 = ref)}
321 + />
322 + <div
323 + onClick={ref => {
324 + actual.push("2nd node clicked imperatively from 1st's handler");
325 + }}
326 + ref={ref => (this.ref2 = ref)}
327 + />
328 + </div>
329 + );
330 + }
331 + }
332 +
333 + var container = document.createElement('div');
334 + ReactDOM.render(<Wrapper />, container);
335 +
336 + const expected = [
337 + '1st node clicked',
338 + "2nd node clicked imperatively from 1st's handler",
339 + ];
340 + expect(actual).toEqual(expected);
341 + });
342 });