Skip to content

Commit 30d44d0

Browse files
committed
Don't couple query-helpers with ByRole
1 parent 94163c1 commit 30d44d0

File tree

1 file changed

+15
-19
lines changed

1 file changed

+15
-19
lines changed

src/query-helpers.ts

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
import {
2-
type AllByRole,
3-
type ByRoleMatcher,
4-
type ByRoleOptions,
1+
import {
52
type GetErrorFunction,
63
type Matcher,
74
type MatcherOptions,
@@ -120,16 +117,16 @@ function makeGetAllQuery<Arguments extends unknown[]>(
120117

121118
// this accepts a getter query function and returns a function which calls
122119
// waitFor and passing a function which invokes the getter.
123-
function makeFindQuery<QueryFor>(
120+
function makeFindQuery<QueryFor, QueryMatcher>(
124121
getter: (
125122
container: HTMLElement,
126-
text: Matcher,
123+
text: QueryMatcher,
127124
options: MatcherOptions,
128125
) => QueryFor,
129126
) {
130127
return (
131128
container: HTMLElement,
132-
text: Matcher,
129+
text: QueryMatcher,
133130
options: MatcherOptions,
134131
waitForOptions: WaitForOptions,
135132
) => {
@@ -212,16 +209,17 @@ const wrapAllByQueryWithSuggestion =
212209
// TODO: This deviates from the published declarations
213210
// However, the implementation always required a dyadic (after `container`) not variadic `queryAllBy` considering the implementation of `makeFindQuery`
214211
// This is at least statically true and can be verified by accepting `QueryMethod<Arguments, HTMLElement[]>`
215-
function buildQueries(
216-
queryAllBy:
217-
| AllByRole
218-
| QueryMethod<[matcher: Matcher, options: MatcherOptions], HTMLElement[]>,
219-
getMultipleError:
220-
| GetErrorFunction<[matcher: ByRoleMatcher, options: ByRoleOptions]>
221-
| GetErrorFunction<[matcher: Matcher, options: MatcherOptions]>,
222-
getMissingError:
223-
| GetErrorFunction<[matcher: ByRoleMatcher, options: ByRoleOptions]>
224-
| GetErrorFunction<[matcher: Matcher, options: MatcherOptions]>,
212+
function buildQueries<QueryMatcher>(
213+
queryAllBy: QueryMethod<
214+
[matcher: QueryMatcher, options: MatcherOptions],
215+
HTMLElement[]
216+
>,
217+
getMultipleError: GetErrorFunction<
218+
[matcher: QueryMatcher, options: MatcherOptions]
219+
>,
220+
getMissingError: GetErrorFunction<
221+
[matcher: QueryMatcher, options: MatcherOptions]
222+
>,
225223
) {
226224
const queryBy = wrapSingleQueryWithSuggestion(
227225
makeSingleQuery(queryAllBy, getMultipleError),
@@ -243,11 +241,9 @@ function buildQueries(
243241
)
244242

245243
const findAllBy = makeFindQuery(
246-
// @ts-expect-error: ByRoleMatcher and ByRoleOptions are not compatible with Matcher and MatcherOptions respectible
247244
wrapAllByQueryWithSuggestion(getAllBy, queryAllBy.name, 'findAll'),
248245
)
249246
const findBy = makeFindQuery(
250-
// @ts-expect-error: ByRoleMatcher and ByRoleOptions are not compatible with Matcher and MatcherOptions respectible
251247
wrapSingleQueryWithSuggestion(getBy, queryAllBy.name, 'find'),
252248
)
253249

0 commit comments

Comments
 (0)