Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #5839 Add error event to source element #6941

Merged
merged 2 commits into from
Jun 8, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -1124,6 +1133,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