@@ -1088,7 +1088,7 @@ ruleTester.run(RULE_NAME, rule, {
1088
1088
( {
1089
1089
code : `
1090
1090
import userEvent from '${ testingFramework } '
1091
- test('unhandled promise from event method called from userEvent.setup() return value is invalid', async () => {
1091
+ test('unhandled promise from event method called from userEvent.setup() return value is invalid', () => {
1092
1092
const user = userEvent.setup();
1093
1093
user.${ eventMethod } (getByLabelText('username'))
1094
1094
})
@@ -1108,6 +1108,150 @@ ruleTester.run(RULE_NAME, rule, {
1108
1108
const user = userEvent.setup();
1109
1109
await user.${ eventMethod } (getByLabelText('username'))
1110
1110
})
1111
+ ` ,
1112
+ } ) as const
1113
+ ) ,
1114
+ // This covers the example in the docs:
1115
+ // https://testing-library.com/docs/user-event/intro#writing-tests-with-userevent
1116
+ ...USER_EVENT_ASYNC_FUNCTIONS . map (
1117
+ ( eventMethod ) =>
1118
+ ( {
1119
+ code : `
1120
+ import userEvent from '${ testingFramework } '
1121
+ test('unhandled promise from event method called from destructured custom setup function is invalid', () => {
1122
+ function customSetup(jsx) {
1123
+ return {
1124
+ user: userEvent.setup(),
1125
+ ...render(jsx)
1126
+ }
1127
+ }
1128
+ const { user } = customSetup(<MyComponent />);
1129
+ user.${ eventMethod } (getByLabelText('username'))
1130
+ })
1131
+ ` ,
1132
+ errors : [
1133
+ {
1134
+ line : 11 ,
1135
+ column : 11 ,
1136
+ messageId : 'awaitAsyncEvent' ,
1137
+ data : { name : eventMethod } ,
1138
+ } ,
1139
+ ] ,
1140
+ options : [ { eventModule : 'userEvent' } ] ,
1141
+ output : `
1142
+ import userEvent from '${ testingFramework } '
1143
+ test('unhandled promise from event method called from destructured custom setup function is invalid', async () => {
1144
+ function customSetup(jsx) {
1145
+ return {
1146
+ user: userEvent.setup(),
1147
+ ...render(jsx)
1148
+ }
1149
+ }
1150
+ const { user } = customSetup(<MyComponent />);
1151
+ await user.${ eventMethod } (getByLabelText('username'))
1152
+ })
1153
+ ` ,
1154
+ } ) as const
1155
+ ) ,
1156
+ ...USER_EVENT_ASYNC_FUNCTIONS . map (
1157
+ ( eventMethod ) =>
1158
+ ( {
1159
+ code : `
1160
+ import userEvent from '${ testingFramework } '
1161
+ test('unhandled promise from aliased event method called from destructured custom setup function is invalid', () => {
1162
+ function customSetup(jsx) {
1163
+ return {
1164
+ foo: userEvent.setup(),
1165
+ bar: userEvent.setup(),
1166
+ ...render(jsx)
1167
+ }
1168
+ }
1169
+ const { foo, bar: myUser } = customSetup(<MyComponent />);
1170
+ myUser.${ eventMethod } (getByLabelText('username'))
1171
+ foo.${ eventMethod } (getByLabelText('username'))
1172
+ })
1173
+ ` ,
1174
+ errors : [
1175
+ {
1176
+ line : 12 ,
1177
+ column : 11 ,
1178
+ messageId : 'awaitAsyncEvent' ,
1179
+ data : { name : eventMethod } ,
1180
+ } ,
1181
+ {
1182
+ line : 13 ,
1183
+ column : 11 ,
1184
+ messageId : 'awaitAsyncEvent' ,
1185
+ data : { name : eventMethod } ,
1186
+ } ,
1187
+ ] ,
1188
+ options : [ { eventModule : 'userEvent' } ] ,
1189
+ output : `
1190
+ import userEvent from '${ testingFramework } '
1191
+ test('unhandled promise from aliased event method called from destructured custom setup function is invalid', async () => {
1192
+ function customSetup(jsx) {
1193
+ return {
1194
+ foo: userEvent.setup(),
1195
+ bar: userEvent.setup(),
1196
+ ...render(jsx)
1197
+ }
1198
+ }
1199
+ const { foo, bar: myUser } = customSetup(<MyComponent />);
1200
+ await myUser.${ eventMethod } (getByLabelText('username'))
1201
+ await foo.${ eventMethod } (getByLabelText('username'))
1202
+ })
1203
+ ` ,
1204
+ } ) as const
1205
+ ) ,
1206
+ ...USER_EVENT_ASYNC_FUNCTIONS . map (
1207
+ ( eventMethod ) =>
1208
+ ( {
1209
+ code : `
1210
+ import userEvent from '${ testingFramework } '
1211
+ test('unhandled promise from setup reference in custom setup function is invalid', () => {
1212
+ function customSetup(jsx) {
1213
+ const u = userEvent.setup()
1214
+ return {
1215
+ foo: u,
1216
+ bar: u,
1217
+ ...render(jsx)
1218
+ }
1219
+ }
1220
+ const { foo, bar: myUser } = customSetup(<MyComponent />);
1221
+ myUser.${ eventMethod } (getByLabelText('username'))
1222
+ foo.${ eventMethod } (getByLabelText('username'))
1223
+ })
1224
+ ` ,
1225
+ errors : [
1226
+ {
1227
+ line : 13 ,
1228
+ column : 11 ,
1229
+ messageId : 'awaitAsyncEvent' ,
1230
+ data : { name : eventMethod } ,
1231
+ } ,
1232
+ {
1233
+ line : 14 ,
1234
+ column : 11 ,
1235
+ messageId : 'awaitAsyncEvent' ,
1236
+ data : { name : eventMethod } ,
1237
+ } ,
1238
+ ] ,
1239
+ options : [ { eventModule : 'userEvent' } ] ,
1240
+ output : `
1241
+ import userEvent from '${ testingFramework } '
1242
+ test('unhandled promise from setup reference in custom setup function is invalid', async () => {
1243
+ function customSetup(jsx) {
1244
+ const u = userEvent.setup()
1245
+ return {
1246
+ foo: u,
1247
+ bar: u,
1248
+ ...render(jsx)
1249
+ }
1250
+ }
1251
+ const { foo, bar: myUser } = customSetup(<MyComponent />);
1252
+ await myUser.${ eventMethod } (getByLabelText('username'))
1253
+ await foo.${ eventMethod } (getByLabelText('username'))
1254
+ })
1111
1255
` ,
1112
1256
} ) as const
1113
1257
) ,
0 commit comments