File tree 3 files changed +26
-12
lines changed
3 files changed +26
-12
lines changed Original file line number Diff line number Diff line change 1
1
import { screen , waitFor } from '@testing-library/dom' ;
2
2
import user from '@testing-library/user-event' ;
3
- import { AllDescriptor , RoleDescriptor , optional } from './roles/types' ;
3
+ import {
4
+ type AllDescriptor ,
5
+ type RoleDescriptor ,
6
+ allKey ,
7
+ optionalKey ,
8
+ } from './roles/types' ;
4
9
5
10
export type DescriptorResult < T > = T extends RoleDescriptor & AllDescriptor
6
11
? Array < HTMLElement >
@@ -30,10 +35,10 @@ export function resolverFor(
30
35
< D extends RoleDescriptor > (
31
36
descriptor : RoleDescriptor | ( RoleDescriptor & AllDescriptor )
32
37
) : D extends AllDescriptor ? ReadonlyArray < HTMLElement > : HTMLElement => {
33
- if ( 'all' in descriptor && descriptor . all === true ) {
38
+ if ( allKey in descriptor ) {
34
39
const { name } = descriptor ;
35
40
return source . queryAllByRole ( descriptor . role , { name } ) as any ;
36
- } else if ( optional in descriptor ) {
41
+ } else if ( optionalKey in descriptor ) {
37
42
const { name, isSelected : selected } = descriptor ;
38
43
return source . queryByRole ( descriptor . role , { name, selected } ) as any ;
39
44
} else {
Original file line number Diff line number Diff line change 1
1
import { prettyDOM } from '@testing-library/dom' ;
2
- import { optional , type AllDescriptor , type RoleDescriptor } from './types' ;
2
+ import {
3
+ type AllDescriptor ,
4
+ type RoleDescriptor ,
5
+ allKey ,
6
+ optionalKey ,
7
+ } from './types' ;
3
8
4
9
export type RoleObject <
5
10
Role extends string ,
@@ -23,10 +28,10 @@ export function role<
23
28
role,
24
29
name,
25
30
get all ( ) : RoleDescriptor & AllDescriptor {
26
- return Object . create ( this , { all : { value : true } } ) ;
31
+ return Object . create ( this , { [ allKey ] : { value : true } } ) ;
27
32
} ,
28
33
get optional ( ) {
29
- return Object . create ( this , { [ optional ] : { value : true } } ) ;
34
+ return Object . create ( this , { [ optionalKey ] : { value : true } } ) ;
30
35
} ,
31
36
get click ( ) : RoleDescriptor {
32
37
return Object . create ( this , { event : { value : 'click' } } ) ;
@@ -42,7 +47,7 @@ export function roleSelectable(role: string, name?: string | RegExp) {
42
47
return Object . create ( this , { isSelected : { value : true } } ) ;
43
48
} ,
44
49
get all ( ) : RoleDescriptor & AllDescriptor {
45
- return Object . create ( this , { all : { value : true } } ) ;
50
+ return Object . create ( this , { [ allKey ] : { value : true } } ) ;
46
51
} ,
47
52
} ) ;
48
53
}
Original file line number Diff line number Diff line change 1
- import { queries , BoundFunctions , Queries } from '@testing-library/dom' ;
1
+ import {
2
+ queries ,
3
+ type BoundFunctions ,
4
+ type Queries ,
5
+ } from '@testing-library/dom' ;
2
6
3
- const all = Symbol ( 'all' ) ;
4
- export const optional = Symbol ( 'optional' ) ;
7
+ export const allKey = Symbol ( 'all' ) ;
8
+ export const optionalKey = Symbol ( 'optional' ) ;
5
9
6
10
export interface RoleDescriptor {
7
11
readonly role : string ;
8
12
readonly name ?: string | RegExp ;
9
- readonly [ optional ] ?: true ;
13
+ readonly [ optionalKey ] ?: true ;
10
14
readonly isSelected ?: boolean ;
11
15
readonly event ?: 'click' ;
12
16
}
13
17
14
18
export interface AllDescriptor {
15
- readonly all : true ;
19
+ readonly [ allKey ] ? : true ;
16
20
}
17
21
18
22
export interface SingleDescriptor < Q extends Queries = typeof queries > {
You can’t perform that action at this time.
0 commit comments