@@ -202,47 +202,47 @@ describe('<ButtonBase />', () => {
202
202
if ( typeof Touch !== 'undefined' ) {
203
203
const touch = new Touch ( { identifier : 0 , target : button , clientX : 0 , clientY : 0 } ) ;
204
204
205
- await act ( async ( ) => fireEvent . touchStart ( button , { touches : [ touch ] } ) ) ;
205
+ fireEvent . touchStart ( button , { touches : [ touch ] } ) ;
206
206
expect ( onTouchStart . callCount ) . to . equal ( 1 ) ;
207
207
208
- await act ( async ( ) => fireEvent . touchEnd ( button , { touches : [ touch ] } ) ) ;
208
+ fireEvent . touchEnd ( button , { touches : [ touch ] } ) ;
209
209
expect ( onTouchEnd . callCount ) . to . equal ( 1 ) ;
210
210
}
211
211
212
212
if ( canFireDragEvents ) {
213
- await act ( async ( ) => fireEvent . dragEnd ( button ) ) ;
213
+ fireEvent . dragEnd ( button ) ;
214
214
expect ( onDragEnd . callCount ) . to . equal ( 1 ) ;
215
215
}
216
216
217
- await act ( async ( ) => fireEvent . mouseDown ( button ) ) ;
217
+ fireEvent . mouseDown ( button ) ;
218
218
expect ( onMouseDown . callCount ) . to . equal ( 1 ) ;
219
219
220
- await act ( async ( ) => fireEvent . mouseUp ( button ) ) ;
220
+ fireEvent . mouseUp ( button ) ;
221
221
expect ( onMouseUp . callCount ) . to . equal ( 1 ) ;
222
222
223
- await act ( async ( ) => fireEvent . contextMenu ( button ) ) ;
223
+ fireEvent . contextMenu ( button ) ;
224
224
expect ( onContextMenu . callCount ) . to . equal ( 1 ) ;
225
225
226
226
await user . click ( button ) ;
227
227
expect ( onClick . callCount ) . to . equal ( 1 ) ;
228
228
229
- act ( ( ) => {
229
+ await act ( async ( ) => {
230
230
button . focus ( ) ;
231
231
} ) ;
232
232
expect ( onFocus . callCount ) . to . equal ( 1 ) ;
233
233
234
- await act ( async ( ) => fireEvent . keyDown ( button ) ) ;
234
+ fireEvent . keyDown ( button ) ;
235
235
expect ( onKeyDown . callCount ) . to . equal ( 1 ) ;
236
236
237
- await act ( async ( ) => fireEvent . keyUp ( button ) ) ;
237
+ fireEvent . keyUp ( button ) ;
238
238
expect ( onKeyUp . callCount ) . to . equal ( 1 ) ;
239
239
240
- act ( ( ) => {
240
+ await act ( async ( ) => {
241
241
button . blur ( ) ;
242
242
} ) ;
243
243
expect ( onBlur . callCount ) . to . equal ( 1 ) ;
244
244
245
- await act ( async ( ) => fireEvent . mouseLeave ( button ) ) ;
245
+ fireEvent . mouseLeave ( button ) ;
246
246
expect ( onMouseLeave . callCount ) . to . equal ( 1 ) ;
247
247
} ) ;
248
248
} ) ;
@@ -942,9 +942,7 @@ describe('<ButtonBase />', () => {
942
942
943
943
await ripple . startFocus ( button ) ;
944
944
945
- act ( ( ) => {
946
- fireEvent . keyDown ( button , { key : 'Enter' } ) ;
947
- } ) ;
945
+ fireEvent . keyDown ( button , { key : 'Enter' } ) ;
948
946
949
947
expect ( container . querySelectorAll ( '.ripple-visible' ) ) . to . have . lengthOf ( 1 ) ;
950
948
@@ -1007,7 +1005,7 @@ describe('<ButtonBase />', () => {
1007
1005
} ) ;
1008
1006
1009
1007
describe ( 'keyboard accessibility for non interactive elements' , ( ) => {
1010
- it ( 'does not call onClick when a spacebar is pressed on the element but prevents the default' , ( ) => {
1008
+ it ( 'does not call onClick when a spacebar is pressed on the element but prevents the default' , async ( ) => {
1011
1009
const onKeyDown = spy ( ) ;
1012
1010
const onClickSpy = spy ( ) ;
1013
1011
const { getByRole } = render (
@@ -1017,19 +1015,20 @@ describe('<ButtonBase />', () => {
1017
1015
) ;
1018
1016
const button = getByRole ( 'button' ) ;
1019
1017
1020
- act ( ( ) => {
1018
+ await act ( async ( ) => {
1021
1019
button . focus ( ) ;
1022
- fireEvent . keyDown ( button , {
1023
- key : ' ' ,
1024
- } ) ;
1020
+ } ) ;
1021
+
1022
+ fireEvent . keyDown ( button , {
1023
+ key : ' ' ,
1025
1024
} ) ;
1026
1025
1027
1026
expect ( onClickSpy . callCount ) . to . equal ( 0 ) ;
1028
1027
expect ( onKeyDown . callCount ) . to . equal ( 1 ) ;
1029
1028
expect ( onKeyDown . firstCall . args [ 0 ] ) . to . have . property ( 'defaultPrevented' , true ) ;
1030
1029
} ) ;
1031
1030
1032
- it ( 'does call onClick when a spacebar is released on the element' , ( ) => {
1031
+ it ( 'does call onClick when a spacebar is released on the element' , async ( ) => {
1033
1032
const onClickSpy = spy ( ) ;
1034
1033
const { getByRole } = render (
1035
1034
< ButtonBase onClick = { onClickSpy } component = "div" >
@@ -1038,18 +1037,19 @@ describe('<ButtonBase />', () => {
1038
1037
) ;
1039
1038
const button = getByRole ( 'button' ) ;
1040
1039
1041
- act ( ( ) => {
1040
+ await act ( async ( ) => {
1042
1041
button . focus ( ) ;
1043
- fireEvent . keyUp ( button , {
1044
- key : ' ' ,
1045
- } ) ;
1042
+ } ) ;
1043
+
1044
+ fireEvent . keyUp ( button , {
1045
+ key : ' ' ,
1046
1046
} ) ;
1047
1047
1048
1048
expect ( onClickSpy . callCount ) . to . equal ( 1 ) ;
1049
1049
expect ( onClickSpy . firstCall . args [ 0 ] ) . to . have . property ( 'defaultPrevented' , false ) ;
1050
1050
} ) ;
1051
1051
1052
- it ( 'does not call onClick when a spacebar is released and the default is prevented' , ( ) => {
1052
+ it ( 'does not call onClick when a spacebar is released and the default is prevented' , async ( ) => {
1053
1053
const onClickSpy = spy ( ) ;
1054
1054
const { getByRole } = render (
1055
1055
< ButtonBase
@@ -1067,17 +1067,18 @@ describe('<ButtonBase />', () => {
1067
1067
) ;
1068
1068
const button = getByRole ( 'button' ) ;
1069
1069
1070
- act ( ( ) => {
1070
+ await act ( async ( ) => {
1071
1071
button . focus ( ) ;
1072
- fireEvent . keyUp ( button , {
1073
- key : ' ' ,
1074
- } ) ;
1072
+ } ) ;
1073
+
1074
+ fireEvent . keyUp ( button , {
1075
+ key : ' ' ,
1075
1076
} ) ;
1076
1077
1077
1078
expect ( onClickSpy . callCount ) . to . equal ( 0 ) ;
1078
1079
} ) ;
1079
1080
1080
- it ( 'calls onClick when Enter is pressed on the element' , ( ) => {
1081
+ it ( 'calls onClick when Enter is pressed on the element' , async ( ) => {
1081
1082
const onClickSpy = spy ( ) ;
1082
1083
const { getByRole } = render (
1083
1084
< ButtonBase onClick = { onClickSpy } component = "div" >
@@ -1086,11 +1087,12 @@ describe('<ButtonBase />', () => {
1086
1087
) ;
1087
1088
const button = getByRole ( 'button' ) ;
1088
1089
1089
- act ( ( ) => {
1090
+ await act ( async ( ) => {
1090
1091
button . focus ( ) ;
1091
- fireEvent . keyDown ( button , {
1092
- key : 'Enter' ,
1093
- } ) ;
1092
+ } ) ;
1093
+
1094
+ fireEvent . keyDown ( button , {
1095
+ key : 'Enter' ,
1094
1096
} ) ;
1095
1097
1096
1098
expect ( onClickSpy . calledOnce ) . to . equal ( true ) ;
@@ -1131,7 +1133,7 @@ describe('<ButtonBase />', () => {
1131
1133
expect ( onClickSpy . callCount ) . to . equal ( 0 ) ;
1132
1134
} ) ;
1133
1135
1134
- it ( 'prevents default with an anchor and empty href' , ( ) => {
1136
+ it ( 'prevents default with an anchor and empty href' , async ( ) => {
1135
1137
const onClickSpy = spy ( ) ;
1136
1138
const { getByRole } = render (
1137
1139
< ButtonBase component = "a" onClick = { onClickSpy } >
@@ -1140,16 +1142,17 @@ describe('<ButtonBase />', () => {
1140
1142
) ;
1141
1143
const button = getByRole ( 'button' ) ;
1142
1144
1143
- act ( ( ) => {
1145
+ await act ( async ( ) => {
1144
1146
button . focus ( ) ;
1145
- fireEvent . keyDown ( button , { key : 'Enter' } ) ;
1146
1147
} ) ;
1147
1148
1149
+ fireEvent . keyDown ( button , { key : 'Enter' } ) ;
1150
+
1148
1151
expect ( onClickSpy . calledOnce ) . to . equal ( true ) ;
1149
1152
expect ( onClickSpy . firstCall . args [ 0 ] ) . to . have . property ( 'defaultPrevented' , true ) ;
1150
1153
} ) ;
1151
1154
1152
- it ( 'should ignore anchors with href' , ( ) => {
1155
+ it ( 'should ignore anchors with href' , async ( ) => {
1153
1156
const onClick = spy ( ) ;
1154
1157
const onKeyDown = spy ( ) ;
1155
1158
const { getByText } = render (
@@ -1159,11 +1162,12 @@ describe('<ButtonBase />', () => {
1159
1162
) ;
1160
1163
const button = getByText ( 'Hello' ) ;
1161
1164
1162
- act ( ( ) => {
1165
+ await act ( async ( ) => {
1163
1166
button . focus ( ) ;
1164
- fireEvent . keyDown ( button , {
1165
- key : 'Enter' ,
1166
- } ) ;
1167
+ } ) ;
1168
+
1169
+ fireEvent . keyDown ( button , {
1170
+ key : 'Enter' ,
1167
1171
} ) ;
1168
1172
1169
1173
expect ( onClick . callCount ) . to . equal ( 0 ) ;
0 commit comments