Skip to content

Commit 1dcee86

Browse files
authored
Regression test for media event bubbling (facebook#19428)
1 parent c9749d3 commit 1dcee86

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

packages/react-dom/src/__tests__/ReactDOMEventListener-test.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -461,4 +461,32 @@ describe('ReactDOMEventListener', () => {
461461
document.body.removeChild(container);
462462
}
463463
});
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+
});
464492
});

0 commit comments

Comments
 (0)