@@ -17,12 +17,9 @@ it('Should call callback when ref connected to the document', () => {
17
17
18
18
expect ( callback ) . not . toBeCalled ( ) ;
19
19
20
- act ( ( ) => {
21
- document . dispatchEvent ( new Event ( 'mousedown' ) ) ;
22
- document . dispatchEvent ( new Event ( 'touchstart' ) ) ;
23
- } ) ;
20
+ act ( ( ) => document . dispatchEvent ( new Event ( 'click' ) ) ) ;
24
21
25
- expect ( callback ) . toBeCalledTimes ( 2 ) ;
22
+ expect ( callback ) . toBeCalledTimes ( 1 ) ;
26
23
} ) ;
27
24
28
25
it ( 'Should call callback when clicked outside the element' , ( ) => {
@@ -33,12 +30,9 @@ it('Should call callback when clicked outside the element', () => {
33
30
34
31
expect ( callback ) . not . toBeCalled ( ) ;
35
32
36
- act ( ( ) => {
37
- document . dispatchEvent ( new Event ( 'mousedown' ) ) ;
38
- document . dispatchEvent ( new Event ( 'touchstart' ) ) ;
39
- } ) ;
33
+ act ( ( ) => document . dispatchEvent ( new Event ( 'click' ) ) ) ;
40
34
41
- expect ( callback ) . toBeCalledTimes ( 2 ) ;
35
+ expect ( callback ) . toBeCalledTimes ( 1 ) ;
42
36
} ) ;
43
37
44
38
it ( 'Should call callback when clicked outside the ref' , ( ) => {
@@ -49,12 +43,9 @@ it('Should call callback when clicked outside the ref', () => {
49
43
50
44
expect ( callback ) . not . toBeCalled ( ) ;
51
45
52
- act ( ( ) => {
53
- document . dispatchEvent ( new Event ( 'mousedown' ) ) ;
54
- document . dispatchEvent ( new Event ( 'touchstart' ) ) ;
55
- } ) ;
46
+ act ( ( ) => document . dispatchEvent ( new Event ( 'click' ) ) ) ;
56
47
57
- expect ( callback ) . toBeCalledTimes ( 2 ) ;
48
+ expect ( callback ) . toBeCalledTimes ( 1 ) ;
58
49
} ) ;
59
50
60
51
it ( 'Should call callback when clicked outside the function that returns an element' , ( ) => {
@@ -65,12 +56,9 @@ it('Should call callback when clicked outside the function that returns an eleme
65
56
66
57
expect ( callback ) . not . toBeCalled ( ) ;
67
58
68
- act ( ( ) => {
69
- document . dispatchEvent ( new Event ( 'mousedown' ) ) ;
70
- document . dispatchEvent ( new Event ( 'touchstart' ) ) ;
71
- } ) ;
59
+ act ( ( ) => document . dispatchEvent ( new Event ( 'click' ) ) ) ;
72
60
73
- expect ( callback ) . toBeCalledTimes ( 2 ) ;
61
+ expect ( callback ) . toBeCalledTimes ( 1 ) ;
74
62
} ) ;
75
63
76
64
it ( 'Should not call callback when clicked inside the ref' , ( ) => {
@@ -80,10 +68,7 @@ it('Should not call callback when clicked inside the ref', () => {
80
68
81
69
renderHook ( ( ) => useClickOutside ( ref , callback ) ) ;
82
70
83
- act ( ( ) => {
84
- ref . current . dispatchEvent ( new Event ( 'mousedown' ) ) ;
85
- ref . current . dispatchEvent ( new Event ( 'touchstart' ) ) ;
86
- } ) ;
71
+ act ( ( ) => ref . current . dispatchEvent ( new Event ( 'click' ) ) ) ;
87
72
88
73
expect ( callback ) . not . toBeCalled ( ) ;
89
74
} ) ;
@@ -96,10 +81,7 @@ it('Should not call callback when clicked inside the element', () => {
96
81
97
82
renderHook ( ( ) => useClickOutside ( element , callback ) ) ;
98
83
99
- act ( ( ) => {
100
- element . dispatchEvent ( new Event ( 'mousedown' ) ) ;
101
- element . dispatchEvent ( new Event ( 'touchstart' ) ) ;
102
- } ) ;
84
+ act ( ( ) => element . dispatchEvent ( new Event ( 'click' ) ) ) ;
103
85
104
86
expect ( callback ) . not . toBeCalled ( ) ;
105
87
} ) ;
@@ -113,10 +95,7 @@ it('Should not call callback when clicked inside the function that returns an el
113
95
114
96
renderHook ( ( ) => useClickOutside ( getElement , callback ) ) ;
115
97
116
- act ( ( ) => {
117
- element . dispatchEvent ( new Event ( 'mousedown' ) ) ;
118
- element . dispatchEvent ( new Event ( 'touchstart' ) ) ;
119
- } ) ;
98
+ act ( ( ) => element . dispatchEvent ( new Event ( 'click' ) ) ) ;
120
99
121
100
expect ( callback ) . not . toBeCalled ( ) ;
122
101
} ) ;
@@ -136,7 +115,7 @@ it('Should call callback when clicked outside the element (multiple targets)', (
136
115
137
116
renderHook ( ( ) => useClickOutside ( [ element , ref , getElement ] , callback ) ) ;
138
117
139
- act ( ( ) => document . dispatchEvent ( new Event ( 'mousedown ' ) ) ) ;
118
+ act ( ( ) => document . dispatchEvent ( new Event ( 'click ' ) ) ) ;
140
119
141
120
expect ( callback ) . toBeCalledTimes ( 1 ) ;
142
121
} ) ;
0 commit comments