@@ -77,8 +77,10 @@ export default createTestingLibraryRule<Options, MessageIds>({
77
77
closestCallExpressionNode . parent
78
78
) ;
79
79
80
- // check direct usage of async query:
81
- // const element = await findByRole('button')
80
+ /**
81
+ * Check direct usage of async query:
82
+ * const element = await findByRole('button');
83
+ */
82
84
if ( references . length === 0 ) {
83
85
if ( ! isPromiseHandled ( identifierNode ) ) {
84
86
context . report ( {
@@ -103,9 +105,11 @@ export default createTestingLibraryRule<Options, MessageIds>({
103
105
}
104
106
}
105
107
106
- // check references usages of async query:
107
- // const promise = findByRole('button')
108
- // const element = await promise
108
+ /**
109
+ * Check references usages of async query:
110
+ * const promise = findByRole('button');
111
+ * const element = await promise;
112
+ */
109
113
for ( const reference of references ) {
110
114
if (
111
115
ASTUtils . isIdentifier ( reference . identifier ) &&
@@ -129,7 +133,7 @@ export default createTestingLibraryRule<Options, MessageIds>({
129
133
functionWrappersNames . includes ( identifierNode . name ) &&
130
134
! isPromiseHandled ( identifierNode )
131
135
) {
132
- // check async queries used within a wrapper previously detected
136
+ // Check async queries used within a wrapper previously detected
133
137
context . report ( {
134
138
node : identifierNode ,
135
139
messageId : 'asyncQueryWrapper' ,
@@ -141,19 +145,23 @@ export default createTestingLibraryRule<Options, MessageIds>({
141
145
if ( ! functionExpression ) return null ;
142
146
143
147
let IdentifierNodeFixer ;
144
- // If the wrapper is a property of an object,
145
- // add 'await' before the object, e.g.:
146
- // const obj = { wrapper: () => screen.findByText(/foo/i) };
147
- // await obj.wrapper();
148
148
if ( isMemberExpression ( identifierNode . parent ) ) {
149
+ /**
150
+ * If the wrapper is a property of an object,
151
+ * add 'await' before the object, e.g.:
152
+ * const obj = { wrapper: () => screen.findByText(/foo/i) };
153
+ * await obj.wrapper();
154
+ */
149
155
IdentifierNodeFixer = fixer . insertTextBefore (
150
156
identifierNode . parent ,
151
157
'await '
152
158
) ;
153
- // Otherwise, add 'await' before the wrapper function, e.g.:
154
- // const wrapper = () => screen.findByText(/foo/i);
155
- // await wrapper();
156
159
} else {
160
+ /**
161
+ * Add 'await' before the wrapper function, e.g.:
162
+ * const wrapper = () => screen.findByText(/foo/i);
163
+ * await wrapper();
164
+ */
157
165
IdentifierNodeFixer = fixer . insertTextBefore (
158
166
identifierNode ,
159
167
'await '
@@ -163,8 +171,10 @@ export default createTestingLibraryRule<Options, MessageIds>({
163
171
if ( functionExpression . async ) {
164
172
return IdentifierNodeFixer ;
165
173
} else {
166
- // Mutate the actual node so if other nodes exist in this
167
- // function expression body they don't also try to fix it.
174
+ /**
175
+ * Mutate the actual node so if other nodes exist in this
176
+ * function expression body they don't also try to fix it.
177
+ */
168
178
functionExpression . async = true ;
169
179
170
180
return [
0 commit comments