@@ -13,32 +13,61 @@ jest.mock('../events/isEventSupported');
13
13
14
14
describe ( 'EventPluginHub' , ( ) => {
15
15
let React ;
16
- let ReactTestUtils ;
16
+ let ReactDOM ;
17
+ let container ;
17
18
18
19
beforeEach ( ( ) => {
19
20
jest . resetModules ( ) ;
20
21
React = require ( 'react' ) ;
21
- ReactTestUtils = require ( 'react-dom/test-utils' ) ;
22
+ ReactDOM = require ( 'react-dom' ) ;
23
+
24
+ container = document . createElement ( 'div' ) ;
25
+ document . body . appendChild ( container ) ;
26
+ } ) ;
27
+
28
+ afterEach ( ( ) => {
29
+ document . body . removeChild ( container ) ;
30
+ container = null ;
22
31
} ) ;
23
32
24
33
it ( 'should prevent non-function listeners, at dispatch' , ( ) => {
25
34
let node ;
26
35
expect ( ( ) => {
27
- node = ReactTestUtils . renderIntoDocument (
28
- < div onClick = "not a function" /> ,
29
- ) ;
36
+ node = ReactDOM . render ( < div onClick = "not a function" /> , container ) ;
30
37
} ) . toWarnDev (
31
38
'Expected `onClick` listener to be a function, instead got a value of `string` type.' ,
32
39
) ;
33
- expect ( ( ) => ReactTestUtils . SimulateNative . click ( node ) ) . toThrowError (
34
- 'Expected `onClick` listener to be a function, instead got a value of `string` type.' ,
40
+
41
+ let uncaughtErrors = [ ] ;
42
+ function handleWindowError ( e ) {
43
+ uncaughtErrors . push ( e . error ) ;
44
+ }
45
+ window . addEventListener ( 'error' , handleWindowError ) ;
46
+ try {
47
+ node . dispatchEvent (
48
+ new MouseEvent ( 'click' , {
49
+ bubbles : true ,
50
+ } ) ,
51
+ ) ;
52
+ } finally {
53
+ window . removeEventListener ( 'error' , handleWindowError ) ;
54
+ }
55
+ expect ( uncaughtErrors . length ) . toBe ( 1 ) ;
56
+ expect ( uncaughtErrors [ 0 ] ) . toEqual (
57
+ expect . objectContaining ( {
58
+ message :
59
+ 'Expected `onClick` listener to be a function, ' +
60
+ 'instead got a value of `string` type.' ,
61
+ } ) ,
35
62
) ;
36
63
} ) ;
37
64
38
65
it ( 'should not prevent null listeners, at dispatch' , ( ) => {
39
- const node = ReactTestUtils . renderIntoDocument ( < div onClick = { null } /> ) ;
40
- expect ( function ( ) {
41
- ReactTestUtils . SimulateNative . click ( node ) ;
42
- } ) . not . toThrow ( ) ;
66
+ const node = ReactDOM . render ( < div onClick = { null } /> , container ) ;
67
+ node . dispatchEvent (
68
+ new MouseEvent ( 'click' , {
69
+ bubbles : true ,
70
+ } ) ,
71
+ ) ;
43
72
} ) ;
44
73
} ) ;
0 commit comments