Skip to content

fix: make sure options types match the of @testing-library/dom #252

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
import { ClientFunction, Selector } from "testcafe";
import { Matcher, queries } from "@testing-library/dom";
import type {
Options,
QueryName,
QueryOptions,
WithinSelectors,
} from "./types";
import type { Options, QueryName, WithinSelectors } from "./types";

declare global {
interface Window {
Expand Down Expand Up @@ -71,9 +66,14 @@ function isSelector(sel: any): sel is Selector {
return sel.constructor.name === SELECTOR_TYPE;
}

const bindFunction = <T extends QueryName>(queryName: T) => {
const bindFunction = <
T extends QueryName,
Options = Parameters<typeof queries[T]>[2]
>(
queryName: T
) => {
const query = queryName.replace("find", "query") as T;
return (matcher: Matcher, options?: QueryOptions) => {
return (matcher: Matcher, options?: Options) => {
return Selector(
() =>
window.TestingLibraryDom[query](document.body, matcher, options) as
Expand Down
11 changes: 1 addition & 10 deletions src/types.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
import {
Config,
BoundFunction,
queries,
Matcher,
MatcherOptions,
} from "@testing-library/dom";
import { Config, BoundFunction, queries } from "@testing-library/dom";

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

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

export type QueryName = keyof typeof queries;

export type QueryOptions = MatcherOptions;

export type WithinSelectors = TestcafeBoundFunctions<typeof queries>;
6 changes: 6 additions & 0 deletions tests/testcafe/screen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,9 @@ test("getByLabelText", async (t) => {
"Hello Input Labelled By Id"
);
});

test("getByRole", async (t) => {
await t.click(
screen.getByRole("textbox", { name: "Label For Input Labelled By Id" })
);
});