1
- import { ClientFunction , Selector } from ' testcafe'
2
- import { queries } from ' @testing-library/dom'
1
+ import { ClientFunction , Selector } from " testcafe" ;
2
+ import { queries } from " @testing-library/dom" ;
3
3
import type {
4
4
Options ,
5
5
TestcafeBoundFunction ,
6
6
TestcafeBoundFunctions ,
7
- } from ' ./types'
7
+ } from " ./types" ;
8
8
9
9
declare global {
10
10
interface Window {
11
- TestingLibraryDom : typeof queries
11
+ TestingLibraryDom : typeof queries ;
12
12
}
13
13
}
14
14
15
- const SELECTOR_TYPE = Selector ( '' ) ( ) . constructor . name
15
+ const SELECTOR_TYPE = Selector ( "" ) ( ) . constructor . name ;
16
16
17
17
const withinSelectors = Object . keys ( queries ) . reduce ( ( acc , withinQueryName ) => {
18
18
return {
@@ -26,109 +26,111 @@ const withinSelectors = Object.keys(queries).reduce((acc, withinQueryName) => {
26
26
const args = Array.from(arguments).slice(1);
27
27
return window.TestingLibraryDom.within(el).${ withinQueryName } .apply(null, args);
28
28
` ) ,
29
- }
30
- } , { } as Record < keyof typeof queries , ( node : Element , ...methodParams : any [ ] ) => any > )
29
+ } ;
30
+ } , { } as Record < keyof typeof queries , ( node : Element , ...methodParams : any [ ] ) => any > ) ;
31
31
32
32
export async function configureOnce ( options : Partial < Options > ) {
33
- const { content} = configure ( options )
33
+ const { content } = configure ( options ) ;
34
34
// @ts -ignore
35
- await ClientFunction ( new Function ( content ) ) ( )
35
+ await ClientFunction ( new Function ( content ) ) ( ) ;
36
36
}
37
37
38
38
export function configure ( options : Partial < Options > ) {
39
39
const configFunction = `
40
40
window.TestingLibraryDom.configure(${ JSON . stringify ( options ) } );
41
- `
42
- return { content : configFunction }
41
+ ` ;
42
+ return { content : configFunction } ;
43
43
}
44
44
45
45
export function within < T > (
46
- sel : string | Selector | SelectorPromise | TestcafeBoundFunction < T > ,
46
+ sel : string | Selector | SelectorPromise | TestcafeBoundFunction < T >
47
47
) : TestcafeBoundFunctions < typeof queries > {
48
48
if ( sel instanceof Function ) {
49
- return within ( sel ( ) )
49
+ return within ( sel ( ) ) ;
50
50
}
51
51
if ( isSelector ( sel ) ) {
52
52
// @ts -ignore
53
- return sel . addCustomMethods ( withinSelectors , { returnDOMNodes : true } )
54
- } else if ( typeof sel === ' string' ) {
55
- return within ( Selector ( sel ) )
53
+ return sel . addCustomMethods ( withinSelectors , { returnDOMNodes : true } ) ;
54
+ } else if ( typeof sel === " string" ) {
55
+ return within ( Selector ( sel ) ) ;
56
56
} else {
57
57
throw new Error (
58
- `"within" only accepts a query (getBy, queryBy, etc), string or testcafe Selector` ,
59
- )
58
+ `"within" only accepts a query (getBy, queryBy, etc), string or testcafe Selector`
59
+ ) ;
60
60
}
61
61
}
62
62
63
63
function isSelector ( sel : any ) : sel is Selector {
64
- return sel . constructor . name === SELECTOR_TYPE
64
+ return sel . constructor . name === SELECTOR_TYPE ;
65
65
}
66
66
67
67
const bindFunction = < T extends keyof typeof queries > ( queryName : T ) => {
68
- const query = queryName . replace ( ' find' , ' query' ) as T
68
+ const query = queryName . replace ( " find" , " query" ) as T ;
69
69
return Selector (
70
70
( matcher , ...options ) => {
71
71
return window . TestingLibraryDom [ query ] (
72
72
document . body ,
73
73
matcher ,
74
- ...options ,
75
- ) as Node | Node [ ] | NodeList | HTMLCollection
74
+ ...options
75
+ ) as Node | Node [ ] | NodeList | HTMLCollection ;
76
76
} ,
77
77
{
78
- dependencies : { query} ,
79
- } ,
80
- )
81
- }
78
+ dependencies : { query } ,
79
+ }
80
+ ) ;
81
+ } ;
82
82
83
- export const getByLabelText = bindFunction ( ' getByLabelText' )
84
- export const getAllByLabelText = bindFunction ( ' getAllByLabelText' )
85
- export const queryByLabelText = bindFunction ( ' queryByLabelText' )
86
- export const queryAllByLabelText = bindFunction ( ' queryAllByLabelText' )
87
- export const findByLabelText = bindFunction ( ' findByLabelText' )
88
- export const findAllByLabelText = bindFunction ( ' findAllByLabelText' )
89
- export const getByPlaceholderText = bindFunction ( ' getByPlaceholderText' )
90
- export const getAllByPlaceholderText = bindFunction ( ' getAllByPlaceholderText' )
91
- export const queryByPlaceholderText = bindFunction ( ' queryByPlaceholderText' )
83
+ export const getByLabelText = bindFunction ( " getByLabelText" ) ;
84
+ export const getAllByLabelText = bindFunction ( " getAllByLabelText" ) ;
85
+ export const queryByLabelText = bindFunction ( " queryByLabelText" ) ;
86
+ export const queryAllByLabelText = bindFunction ( " queryAllByLabelText" ) ;
87
+ export const findByLabelText = bindFunction ( " findByLabelText" ) ;
88
+ export const findAllByLabelText = bindFunction ( " findAllByLabelText" ) ;
89
+ export const getByPlaceholderText = bindFunction ( " getByPlaceholderText" ) ;
90
+ export const getAllByPlaceholderText = bindFunction ( " getAllByPlaceholderText" ) ;
91
+ export const queryByPlaceholderText = bindFunction ( " queryByPlaceholderText" ) ;
92
92
export const queryAllByPlaceholderText = bindFunction (
93
- 'queryAllByPlaceholderText' ,
94
- )
95
- export const findByPlaceholderText = bindFunction ( 'findByPlaceholderText' )
96
- export const findAllByPlaceholderText = bindFunction ( 'findAllByPlaceholderText' )
97
- export const getByText = bindFunction ( 'getByText' )
98
- export const getAllByText = bindFunction ( 'getAllByText' )
99
- export const queryByText = bindFunction ( 'queryByText' )
100
- export const queryAllByText = bindFunction ( 'queryAllByText' )
101
- export const findByText = bindFunction ( 'findByText' )
102
- export const findAllByText = bindFunction ( 'findAllByText' )
103
- export const getByAltText = bindFunction ( 'getByAltText' )
104
- export const getAllByAltText = bindFunction ( 'getAllByAltText' )
105
- export const queryByAltText = bindFunction ( 'queryByAltText' )
106
- export const queryAllByAltText = bindFunction ( 'queryAllByAltText' )
107
- export const findByAltText = bindFunction ( 'findByAltText' )
108
- export const findAllByAltText = bindFunction ( 'findAllByAltText' )
109
- export const getByTitle = bindFunction ( 'getByTitle' )
110
- export const getAllByTitle = bindFunction ( 'getAllByTitle' )
111
- export const queryByTitle = bindFunction ( 'queryByTitle' )
112
- export const queryAllByTitle = bindFunction ( 'queryAllByTitle' )
113
- export const findByTitle = bindFunction ( 'findByTitle' )
114
- export const findAllByTitle = bindFunction ( 'findAllByTitle' )
115
- export const getByDisplayValue = bindFunction ( 'getByDisplayValue' )
116
- export const getAllByDisplayValue = bindFunction ( 'getAllByDisplayValue' )
117
- export const queryByDisplayValue = bindFunction ( 'queryByDisplayValue' )
118
- export const queryAllByDisplayValue = bindFunction ( 'queryAllByDisplayValue' )
119
- export const findByDisplayValue = bindFunction ( 'findByDisplayValue' )
120
- export const getByRole = bindFunction ( 'getByRole' )
121
- export const getAllByRole = bindFunction ( 'getAllByRole' )
122
- export const queryByRole = bindFunction ( 'queryByRole' )
123
- export const queryAllByRole = bindFunction ( 'queryAllByRole' )
124
- export const findByRole = bindFunction ( 'findByRole' )
125
- export const findAllByRole = bindFunction ( 'findAllByRole' )
126
- export const findAllByDisplayValue = bindFunction ( 'findAllByDisplayValue' )
127
- export const getByTestId = bindFunction ( 'getByTestId' )
128
- export const getAllByTestId = bindFunction ( 'getAllByTestId' )
129
- export const queryByTestId = bindFunction ( 'queryByTestId' )
130
- export const queryAllByTestId = bindFunction ( 'queryAllByTestId' )
131
- export const findByTestId = bindFunction ( 'findByTestId' )
132
- export const findAllByTestId = bindFunction ( 'findAllByTestId' )
93
+ "queryAllByPlaceholderText"
94
+ ) ;
95
+ export const findByPlaceholderText = bindFunction ( "findByPlaceholderText" ) ;
96
+ export const findAllByPlaceholderText = bindFunction (
97
+ "findAllByPlaceholderText"
98
+ ) ;
99
+ export const getByText = bindFunction ( "getByText" ) ;
100
+ export const getAllByText = bindFunction ( "getAllByText" ) ;
101
+ export const queryByText = bindFunction ( "queryByText" ) ;
102
+ export const queryAllByText = bindFunction ( "queryAllByText" ) ;
103
+ export const findByText = bindFunction ( "findByText" ) ;
104
+ export const findAllByText = bindFunction ( "findAllByText" ) ;
105
+ export const getByAltText = bindFunction ( "getByAltText" ) ;
106
+ export const getAllByAltText = bindFunction ( "getAllByAltText" ) ;
107
+ export const queryByAltText = bindFunction ( "queryByAltText" ) ;
108
+ export const queryAllByAltText = bindFunction ( "queryAllByAltText" ) ;
109
+ export const findByAltText = bindFunction ( "findByAltText" ) ;
110
+ export const findAllByAltText = bindFunction ( "findAllByAltText" ) ;
111
+ export const getByTitle = bindFunction ( "getByTitle" ) ;
112
+ export const getAllByTitle = bindFunction ( "getAllByTitle" ) ;
113
+ export const queryByTitle = bindFunction ( "queryByTitle" ) ;
114
+ export const queryAllByTitle = bindFunction ( "queryAllByTitle" ) ;
115
+ export const findByTitle = bindFunction ( "findByTitle" ) ;
116
+ export const findAllByTitle = bindFunction ( "findAllByTitle" ) ;
117
+ export const getByDisplayValue = bindFunction ( "getByDisplayValue" ) ;
118
+ export const getAllByDisplayValue = bindFunction ( "getAllByDisplayValue" ) ;
119
+ export const queryByDisplayValue = bindFunction ( "queryByDisplayValue" ) ;
120
+ export const queryAllByDisplayValue = bindFunction ( "queryAllByDisplayValue" ) ;
121
+ export const findByDisplayValue = bindFunction ( "findByDisplayValue" ) ;
122
+ export const getByRole = bindFunction ( "getByRole" ) ;
123
+ export const getAllByRole = bindFunction ( "getAllByRole" ) ;
124
+ export const queryByRole = bindFunction ( "queryByRole" ) ;
125
+ export const queryAllByRole = bindFunction ( "queryAllByRole" ) ;
126
+ export const findByRole = bindFunction ( "findByRole" ) ;
127
+ export const findAllByRole = bindFunction ( "findAllByRole" ) ;
128
+ export const findAllByDisplayValue = bindFunction ( "findAllByDisplayValue" ) ;
129
+ export const getByTestId = bindFunction ( "getByTestId" ) ;
130
+ export const getAllByTestId = bindFunction ( "getAllByTestId" ) ;
131
+ export const queryByTestId = bindFunction ( "queryByTestId" ) ;
132
+ export const queryAllByTestId = bindFunction ( "queryAllByTestId" ) ;
133
+ export const findByTestId = bindFunction ( "findByTestId" ) ;
134
+ export const findAllByTestId = bindFunction ( "findAllByTestId" ) ;
133
135
134
- export * from ' ./types'
136
+ export * from " ./types" ;
0 commit comments