Skip to content

Commit

Permalink
Fix #5839 Add error event to source element (#6941)
Browse files Browse the repository at this point in the history
* Fix #5839 Add error event to source element

* Add test case for <source onError={callback}>
  • Loading branch information
wadahiro authored and jimfb committed Jun 8, 2016
1 parent 99d8524 commit 518336e
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/renderers/dom/shared/ReactDOMComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,15 @@ function trapBubbledEventsLocal() {
);
}
}

break;
case 'source':
inst._wrapperState.listeners = [
ReactBrowserEventEmitter.trapBubbledEvent(
EventConstants.topLevelTypes.topError,
'error',
node
),
];
break;
case 'img':
inst._wrapperState.listeners = [
Expand Down Expand Up @@ -535,6 +543,7 @@ ReactDOMComponent.Mixin = {
case 'img':
case 'link':
case 'object':
case 'source':
case 'video':
this._wrapperState = {
listeners: null,
Expand Down Expand Up @@ -1143,6 +1152,7 @@ ReactDOMComponent.Mixin = {
case 'img':
case 'link':
case 'object':
case 'source':
case 'video':
var listeners = this._wrapperState.listeners;
if (listeners) {
Expand Down
20 changes: 20 additions & 0 deletions src/renderers/dom/shared/__tests__/ReactDOMComponent-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -723,6 +723,26 @@ describe('ReactDOMComponent', function() {
};
});

it('should work error event on <source> element', function() {
spyOn(console, 'error');
var container = document.createElement('div');
ReactDOM.render(
<video>
<source src="http://example.org/video" type="video/mp4" onError={(e) => console.error('onError called')} />
</video>,
container
);

var errorEvent = document.createEvent('Event');
errorEvent.initEvent('error', false, false);
container.getElementsByTagName('source')[0].dispatchEvent(errorEvent);

expect(console.error.calls.count()).toBe(1);
expect(console.error.calls.argsFor(0)[0]).toContain(
'onError called'
);
});

it('should not duplicate uppercased selfclosing tags', function() {
var Container = React.createClass({
render: function() {
Expand Down

0 comments on commit 518336e

Please sign in to comment.