Skip to content

Commit 6d655d2

Browse files
timmakTim Pinington
and
Tim Pinington
authored
fix: make sure options types match the of @testing-library/dom (#252)
Co-authored-by: Tim Pinington <[email protected]>
1 parent 8e632d5 commit 6d655d2

File tree

3 files changed

+15
-18
lines changed

3 files changed

+15
-18
lines changed

src/index.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
11
import { ClientFunction, Selector } from "testcafe";
22
import { Matcher, queries } from "@testing-library/dom";
3-
import type {
4-
Options,
5-
QueryName,
6-
QueryOptions,
7-
WithinSelectors,
8-
} from "./types";
3+
import type { Options, QueryName, WithinSelectors } from "./types";
94

105
declare global {
116
interface Window {
@@ -71,9 +66,14 @@ function isSelector(sel: any): sel is Selector {
7166
return sel.constructor.name === SELECTOR_TYPE;
7267
}
7368

74-
const bindFunction = <T extends QueryName>(queryName: T) => {
69+
const bindFunction = <
70+
T extends QueryName,
71+
Options = Parameters<typeof queries[T]>[2]
72+
>(
73+
queryName: T
74+
) => {
7575
const query = queryName.replace("find", "query") as T;
76-
return (matcher: Matcher, options?: QueryOptions) => {
76+
return (matcher: Matcher, options?: Options) => {
7777
return Selector(
7878
() =>
7979
window.TestingLibraryDom[query](document.body, matcher, options) as

src/types.ts

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,4 @@
1-
import {
2-
Config,
3-
BoundFunction,
4-
queries,
5-
Matcher,
6-
MatcherOptions,
7-
} from "@testing-library/dom";
1+
import { Config, BoundFunction, queries } from "@testing-library/dom";
82

93
export type Options = Pick<Config, "testIdAttribute">;
104

@@ -17,7 +11,4 @@ export type TestcafeBoundFunctions<T> = {
1711
};
1812

1913
export type QueryName = keyof typeof queries;
20-
21-
export type QueryOptions = MatcherOptions;
22-
2314
export type WithinSelectors = TestcafeBoundFunctions<typeof queries>;

tests/testcafe/screen.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,9 @@ test("getByLabelText", async (t) => {
1919
"Hello Input Labelled By Id"
2020
);
2121
});
22+
23+
test("getByRole", async (t) => {
24+
await t.click(
25+
screen.getByRole("textbox", { name: "Label For Input Labelled By Id" })
26+
);
27+
});

0 commit comments

Comments
 (0)