@@ -756,28 +756,26 @@ describe('ReactDOMComponent', () => {
756
756
} ;
757
757
} ) ;
758
758
759
- // We do not attach DOM listeners when not using create element
760
759
it ( 'should work error event on <source> element' , ( ) => {
760
+ spyOn ( console , 'error' ) ;
761
761
var container = document . createElement ( 'div' ) ;
762
- var onError = jest . fn ( ) ;
763
-
764
762
ReactDOM . render (
765
763
< video >
766
764
< source
767
765
src = "http://example.org/video"
768
766
type = "video/mp4"
769
- onError = { ( ) => onError ( 'onError called' ) }
767
+ onError = { e => console . error ( 'onError called' ) }
770
768
/>
771
769
</ video > ,
772
770
container ,
773
771
) ;
774
772
775
773
var errorEvent = document . createEvent ( 'Event' ) ;
776
774
errorEvent . initEvent ( 'error' , false , false ) ;
777
- container . querySelector ( 'source' ) . dispatchEvent ( errorEvent ) ;
775
+ container . getElementsByTagName ( 'source' ) [ 0 ] . dispatchEvent ( errorEvent ) ;
778
776
779
- expect ( onError ) . toHaveBeenCalledTimes ( 1 ) ;
780
- expect ( onError ) . toHaveBeenCalledWith ( 'onError called' ) ;
777
+ expectDev ( console . error . calls . count ( ) ) . toBe ( 1 ) ;
778
+ expectDev ( console . error . calls . argsFor ( 0 ) [ 0 ] ) . toContain ( 'onError called' ) ;
781
779
} ) ;
782
780
783
781
it ( 'should not duplicate uppercased selfclosing tags' , ( ) => {
@@ -1057,33 +1055,31 @@ describe('ReactDOMComponent', () => {
1057
1055
} ) ;
1058
1056
1059
1057
it ( 'should work load and error events on <image> element in SVG' , ( ) => {
1060
- var onError = jest . fn ( ) ;
1061
- var onLoad = jest . fn ( ) ;
1062
-
1058
+ spyOn ( console , 'log' ) ;
1063
1059
var container = document . createElement ( 'div' ) ;
1064
1060
ReactDOM . render (
1065
1061
< svg >
1066
1062
< image
1067
1063
xlinkHref = "http://example.org/image"
1068
- onError = { ( ) => onError ( 'onError called' ) }
1069
- onLoad = { ( ) => onLoad ( 'onLoad called' ) }
1064
+ onError = { e => console . log ( 'onError called' ) }
1065
+ onLoad = { e => console . log ( 'onLoad called' ) }
1070
1066
/>
1071
1067
</ svg > ,
1072
1068
container ,
1073
1069
) ;
1074
1070
1075
- var loadEvent = new Event ( 'load' ) ;
1076
- var errorEvent = new Event ( 'error' ) ;
1077
- var image = container . querySelector ( 'image' ) ;
1071
+ var loadEvent = document . createEvent ( 'Event' ) ;
1072
+ var errorEvent = document . createEvent ( 'Event' ) ;
1078
1073
1079
- image . dispatchEvent ( errorEvent ) ;
1080
- image . dispatchEvent ( loadEvent ) ;
1074
+ loadEvent . initEvent ( 'load' , false , false ) ;
1075
+ errorEvent . initEvent ( 'error' , false , false ) ;
1081
1076
1082
- expect ( onError ) . toHaveBeenCalledTimes ( 1 ) ;
1083
- expect ( onError ) . toHaveBeenCalledWith ( 'onError called' ) ;
1077
+ container . getElementsByTagName ( 'image' ) [ 0 ] . dispatchEvent ( errorEvent ) ;
1078
+ container . getElementsByTagName ( 'image' ) [ 0 ] . dispatchEvent ( loadEvent ) ;
1084
1079
1085
- expect ( onLoad ) . toHaveBeenCalledTimes ( 1 ) ;
1086
- expect ( onLoad ) . toHaveBeenCalledWith ( 'onLoad called' ) ;
1080
+ expectDev ( console . log . calls . count ( ) ) . toBe ( 2 ) ;
1081
+ expectDev ( console . log . calls . argsFor ( 0 ) [ 0 ] ) . toContain ( 'onError called' ) ;
1082
+ expectDev ( console . log . calls . argsFor ( 1 ) [ 0 ] ) . toContain ( 'onLoad called' ) ;
1087
1083
} ) ;
1088
1084
} ) ;
1089
1085
0 commit comments