Skip to content
This repository was archived by the owner on Aug 6, 2025. It is now read-only.

Commit a54843e

Browse files
authored
refactor: define getQueriesForElement functions using Array of keys (#28)
1 parent 2a920e1 commit a54843e

File tree

1 file changed

+45
-40
lines changed

1 file changed

+45
-40
lines changed

lib/index.ts

Lines changed: 45 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -136,48 +136,53 @@ export function getQueriesForElement<T>(
136136
): T & IQueryUtils & IScopedQueryUtils {
137137
const o = object as any
138138
if (!contextFn) contextFn = () => o
139-
o.getQueriesForElement = () => getQueriesForElement(o, () => o)
140139

141-
o.queryByPlaceholderText = createDelegateFor('queryByPlaceholderText', contextFn)
142-
o.queryAllByPlaceholderText = createDelegateFor('queryAllByPlaceholderText', contextFn)
143-
o.getByPlaceholderText = createDelegateFor('getByPlaceholderText', contextFn)
144-
o.getAllByPlaceholderText = createDelegateFor('getAllByPlaceholderText', contextFn)
145-
146-
o.queryByText = createDelegateFor('queryByText', contextFn)
147-
o.queryAllByText = createDelegateFor('queryAllByText', contextFn)
148-
o.getByText = createDelegateFor('getByText', contextFn)
149-
o.getAllByText = createDelegateFor('getAllByText', contextFn)
150-
151-
o.queryByLabelText = createDelegateFor('queryByLabelText', contextFn)
152-
o.queryAllByLabelText = createDelegateFor('queryAllByLabelText', contextFn)
153-
o.getByLabelText = createDelegateFor('getByLabelText', contextFn)
154-
o.getAllByLabelText = createDelegateFor('getAllByLabelText', contextFn)
155-
156-
o.queryByAltText = createDelegateFor('queryByAltText', contextFn)
157-
o.queryAllByAltText = createDelegateFor('queryAllByAltText', contextFn)
158-
o.getByAltText = createDelegateFor('getByAltText', contextFn)
159-
o.getAllByAltText = createDelegateFor('getAllByAltText', contextFn)
160-
161-
o.queryByTestId = createDelegateFor('queryByTestId', contextFn)
162-
o.queryAllByTestId = createDelegateFor('queryAllByTestId', contextFn)
163-
o.getByTestId = createDelegateFor('getByTestId', contextFn)
164-
o.getAllByTestId = createDelegateFor('getAllByTestId', contextFn)
165-
166-
o.queryByTitle = createDelegateFor('queryByTitle', contextFn)
167-
o.queryAllByTitle = createDelegateFor('queryAllByTitle', contextFn)
168-
o.getByTitle = createDelegateFor('getByTitle', contextFn)
169-
o.getAllByTitle = createDelegateFor('getAllByTitle', contextFn)
170-
171-
o.queryByRole = createDelegateFor('queryByRole', contextFn)
172-
o.queryAllByRole = createDelegateFor('queryAllByRole', contextFn)
173-
o.getByRole = createDelegateFor('getByRole', contextFn)
174-
o.getAllByRole = createDelegateFor('getAllByRole', contextFn)
175-
176-
o.queryByDisplayValue = createDelegateFor('queryByDisplayValue', contextFn)
177-
o.queryAllByDisplayValue = createDelegateFor('queryAllByDisplayValue', contextFn)
178-
o.getByDisplayValue = createDelegateFor('getByDisplayValue', contextFn)
179-
o.getAllByDisplayValue = createDelegateFor('getAllByDisplayValue', contextFn)
140+
const functionNames: Array<keyof IQueryUtils> = [
141+
'queryByPlaceholderText',
142+
'queryAllByPlaceholderText',
143+
'getByPlaceholderText',
144+
'getAllByPlaceholderText',
145+
146+
'queryByText',
147+
'queryAllByText',
148+
'getByText',
149+
'getAllByText',
150+
151+
'queryByLabelText',
152+
'queryAllByLabelText',
153+
'getByLabelText',
154+
'getAllByLabelText',
155+
156+
'queryByAltText',
157+
'queryAllByAltText',
158+
'getByAltText',
159+
'getAllByAltText',
160+
161+
'queryByTestId',
162+
'queryAllByTestId',
163+
'getByTestId',
164+
'getAllByTestId',
165+
166+
'queryByTitle',
167+
'queryAllByTitle',
168+
'getByTitle',
169+
'getAllByTitle',
170+
171+
'queryByRole',
172+
'queryAllByRole',
173+
'getByRole',
174+
'getAllByRole',
175+
176+
'queryByDisplayValue',
177+
'queryAllByDisplayValue',
178+
'getByDisplayValue',
179+
'getAllByDisplayValue',
180+
]
181+
functionNames.forEach(functionName => {
182+
o[functionName] = createDelegateFor(functionName, contextFn)
183+
})
180184

185+
o.getQueriesForElement = () => getQueriesForElement(o, () => o)
181186
o.getNodeText = createDelegateFor<string>('getNodeText', contextFn, processNodeText)
182187

183188
return o

0 commit comments

Comments
 (0)