Skip to content

Commit

Permalink
Regression test for media event bubbling (facebook#19428)
Browse files Browse the repository at this point in the history
  • Loading branch information
gaearon committed Jul 21, 2020
1 parent c9749d3 commit 1dcee86
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions packages/react-dom/src/__tests__/ReactDOMEventListener-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -461,4 +461,32 @@ describe('ReactDOMEventListener', () => {
document.body.removeChild(container);
}
});

// Unlike browsers, we delegate media events.
// (This doesn't make a lot of sense but it would be a breaking change not to.)
it('should delegate media events even without a direct listener', () => {
const container = document.createElement('div');
const ref = React.createRef();
const handleVideoPlayDelegated = jest.fn();
document.body.appendChild(container);
try {
ReactDOM.render(
<div onPlay={handleVideoPlayDelegated}>
{/* Intentionally no handler on the target: */}
<video ref={ref} />
</div>,
container,
);
ref.current.dispatchEvent(
new Event('play', {
bubbles: false,
}),
);
// Regression test: ensure React tree delegation still works
// even if the actual DOM element did not have a handler.
expect(handleVideoPlayDelegated).toHaveBeenCalledTimes(1);
} finally {
document.body.removeChild(container);
}
});
});

0 comments on commit 1dcee86

Please sign in to comment.