@@ -965,33 +965,6 @@ describe('ReactDOMComponent', () => {
965965 } ;
966966 } ) ;
967967
968- it ( 'should work error event on <source> element' , ( ) => {
969- const onError = jest . fn ( ) ;
970- const container = document . createElement ( 'div' ) ;
971- ReactDOM . render (
972- < video >
973- < source
974- src = "http://example.org/video"
975- type = "video/mp4"
976- onError = { onError }
977- />
978- </ video > ,
979- container ,
980- ) ;
981-
982- try {
983- document . body . appendChild ( container ) ;
984-
985- const errorEvent = document . createEvent ( 'Event' ) ;
986- errorEvent . initEvent ( 'error' , false , false ) ;
987- container . getElementsByTagName ( 'source' ) [ 0 ] . dispatchEvent ( errorEvent ) ;
988-
989- expect ( onError ) . toHaveBeenCalledTimes ( 1 ) ;
990- } finally {
991- container . remove ( ) ;
992- }
993- } ) ;
994-
995968 it ( 'should not duplicate uppercased selfclosing tags' , ( ) => {
996969 class Container extends React . Component {
997970 render ( ) {
@@ -2443,4 +2416,74 @@ describe('ReactDOMComponent', () => {
24432416 expect ( node . getAttribute ( 'onx' ) ) . toBe ( 'bar' ) ;
24442417 } ) ;
24452418 } ) ;
2419+
2420+ describe ( 'when dispatching events' , ( ) => {
2421+ it ( 'should receive error events on <source> elements' , ( ) => {
2422+ const onError = jest . fn ( ) ;
2423+ const container = document . createElement ( 'div' ) ;
2424+
2425+ ReactDOM . render (
2426+ < video >
2427+ < source
2428+ src = "http://example.org/video"
2429+ type = "video/mp4"
2430+ onError = { onError }
2431+ />
2432+ </ video > ,
2433+ container ,
2434+ ) ;
2435+
2436+ try {
2437+ document . body . appendChild ( container ) ;
2438+
2439+ const errorEvent = document . createEvent ( 'Event' ) ;
2440+ errorEvent . initEvent ( 'error' , false , false ) ;
2441+ container . getElementsByTagName ( 'source' ) [ 0 ] . dispatchEvent ( errorEvent ) ;
2442+
2443+ expect ( onError ) . toHaveBeenCalledTimes ( 1 ) ;
2444+ } finally {
2445+ container . remove ( ) ;
2446+ }
2447+ } ) ;
2448+
2449+ it ( 'receives events in the correct order' , ( ) => {
2450+ let eventOrder = [ ] ;
2451+ let track = tag => ( ) => eventOrder . push ( tag ) ;
2452+
2453+ class TestCase extends React . Component {
2454+ componentDidMount ( ) {
2455+ document . addEventListener ( 'click' , track ( 'document bubble' ) ) ;
2456+ document . addEventListener ( 'click' , track ( 'document capture' ) , true ) ;
2457+ }
2458+ render ( ) {
2459+ return (
2460+ < div
2461+ onClick = { track ( 'element bubble' ) }
2462+ onClickCapture = { track ( 'element capture' ) }
2463+ />
2464+ ) ;
2465+ }
2466+ }
2467+
2468+ const container = document . createElement ( 'div' ) ;
2469+ ReactDOM . render ( < TestCase /> , container ) ;
2470+
2471+ try {
2472+ document . body . appendChild ( container ) ;
2473+
2474+ const errorEvent = document . createEvent ( 'Event' ) ;
2475+ errorEvent . initEvent ( 'click' , true , true ) ;
2476+ container . querySelector ( 'div' ) . dispatchEvent ( errorEvent ) ;
2477+
2478+ expect ( eventOrder ) . toEqual ( [
2479+ 'document capture' ,
2480+ 'element capture' ,
2481+ 'element bubble' ,
2482+ 'document bubble' ,
2483+ ] ) ;
2484+ } finally {
2485+ container . remove ( ) ;
2486+ }
2487+ } ) ;
2488+ } ) ;
24462489} ) ;
0 commit comments