@samitouri / QOS-React-2 / commits / 1dcee86565

Regression test for media event bubbling (#19428)

Dan Abramov committed Jul 21, 2020 at 22:26 UTC 1dcee8656523668038551b3d1b69f7d679e769f8
1 file changed +28
packages/react-dom/src/__tests__/ReactDOMEventListener-test.js
+28
@@ -461,4 +461,32 @@ describe('ReactDOMEventListener', () => {
461 document.body.removeChild(container);
462 }
463 });
464 +
465 + // Unlike browsers, we delegate media events.
466 + // (This doesn't make a lot of sense but it would be a breaking change not to.)
467 + it('should delegate media events even without a direct listener', () => {
468 + const container = document.createElement('div');
469 + const ref = React.createRef();
470 + const handleVideoPlayDelegated = jest.fn();
471 + document.body.appendChild(container);
472 + try {
473 + ReactDOM.render(
474 + <div onPlay={handleVideoPlayDelegated}>
475 + {/* Intentionally no handler on the target: */}
476 + <video ref={ref} />
477 + </div>,
478 + container,
479 + );
480 + ref.current.dispatchEvent(
481 + new Event('play', {
482 + bubbles: false,
483 + }),
484 + );
485 + // Regression test: ensure React tree delegation still works
486 + // even if the actual DOM element did not have a handler.
487 + expect(handleVideoPlayDelegated).toHaveBeenCalledTimes(1);
488 + } finally {
489 + document.body.removeChild(container);
490 + }
491 + });
492 });