9
9
isObjectPattern ,
10
10
isProperty ,
11
11
} from '../node-utils' ;
12
- import { getSourceCode } from '../utils' ;
12
+ import { getScope , getSourceCode } from '../utils' ;
13
13
14
14
export const RULE_NAME = 'prefer-find-by' ;
15
15
export type MessageIds = 'preferFindBy' ;
@@ -119,7 +119,7 @@ export default createTestingLibraryRule<Options, MessageIds>({
119
119
isCallExpression ( node . body . callee . object . arguments [ 0 ] ) &&
120
120
ASTUtils . isIdentifier ( node . body . callee . object . arguments [ 0 ] . callee )
121
121
) {
122
- return node . body . callee . object . arguments [ 0 ] . callee . name ;
122
+ return node . body . callee . object . arguments [ 0 ] . callee ;
123
123
}
124
124
125
125
if ( ! ASTUtils . isIdentifier ( node . body . callee . property ) ) {
@@ -135,7 +135,7 @@ export default createTestingLibraryRule<Options, MessageIds>({
135
135
node . body . callee . object . arguments [ 0 ] . callee . property
136
136
)
137
137
) {
138
- return node . body . callee . object . arguments [ 0 ] . callee . property . name ;
138
+ return node . body . callee . object . arguments [ 0 ] . callee . property ;
139
139
}
140
140
141
141
// expect(screen.getByText).not shape
@@ -150,7 +150,7 @@ export default createTestingLibraryRule<Options, MessageIds>({
150
150
node . body . callee . object . object . arguments [ 0 ] . callee . property
151
151
)
152
152
) {
153
- return node . body . callee . object . object . arguments [ 0 ] . callee . property . name ;
153
+ return node . body . callee . object . object . arguments [ 0 ] . callee . property ;
154
154
}
155
155
156
156
// expect(getByText).not shape
@@ -162,10 +162,10 @@ export default createTestingLibraryRule<Options, MessageIds>({
162
162
node . body . callee . object . object . arguments [ 0 ] . callee
163
163
)
164
164
) {
165
- return node . body . callee . object . object . arguments [ 0 ] . callee . name ;
165
+ return node . body . callee . object . object . arguments [ 0 ] . callee ;
166
166
}
167
167
168
- return node . body . callee . property . name ;
168
+ return node . body . callee . property ;
169
169
}
170
170
171
171
function getWrongQueryName ( node : TSESTree . ArrowFunctionExpression ) {
@@ -178,7 +178,7 @@ export default createTestingLibraryRule<Options, MessageIds>({
178
178
ASTUtils . isIdentifier ( node . body . callee ) &&
179
179
helpers . isSyncQuery ( node . body . callee )
180
180
) {
181
- return node . body . callee . name ;
181
+ return node . body . callee ;
182
182
}
183
183
184
184
return getWrongQueryNameInAssertion ( node ) ;
@@ -354,12 +354,14 @@ export default createTestingLibraryRule<Options, MessageIds>({
354
354
}
355
355
356
356
// shape of () => screen.getByText
357
- const fullQueryMethod = getWrongQueryName ( argument ) ;
357
+ const fullQueryMethodNode = getWrongQueryName ( argument ) ;
358
358
359
- if ( ! fullQueryMethod ) {
359
+ if ( ! fullQueryMethodNode ) {
360
360
return ;
361
361
}
362
362
363
+ const fullQueryMethod = fullQueryMethodNode . name ;
364
+
363
365
// if there is a second argument to AwaitExpression, it is the options
364
366
const waitOptions = node . arguments [ 1 ] ;
365
367
let waitOptionsSourceCode = '' ;
@@ -401,12 +403,14 @@ export default createTestingLibraryRule<Options, MessageIds>({
401
403
}
402
404
403
405
// shape of () => getByText
404
- const fullQueryMethod = getWrongQueryName ( argument ) ;
406
+ const fullQueryMethodNode = getWrongQueryName ( argument ) ;
405
407
406
- if ( ! fullQueryMethod ) {
408
+ if ( ! fullQueryMethodNode ) {
407
409
return ;
408
410
}
409
411
412
+ const fullQueryMethod = fullQueryMethodNode . name ;
413
+
410
414
const queryMethod = fullQueryMethod . split ( 'By' ) [ 1 ] ;
411
415
const queryVariant = getFindByQueryVariant ( fullQueryMethod ) ;
412
416
const callArguments = getQueryArguments ( argument . body ) ;
@@ -435,7 +439,7 @@ export default createTestingLibraryRule<Options, MessageIds>({
435
439
436
440
// this adds the findBy* declaration - adding it to the list of destructured variables { findBy* } = render()
437
441
const definition = findRenderDefinitionDeclaration (
438
- context . getScope ( ) ,
442
+ getScope ( context , fullQueryMethodNode ) ,
439
443
fullQueryMethod
440
444
) ;
441
445
// I think it should always find it, otherwise code should not be valid (it'd be using undeclared variables)
0 commit comments