diff --git a/.eslintrc b/.eslintrc index 12a802f..47675b5 100644 --- a/.eslintrc +++ b/.eslintrc @@ -6,6 +6,8 @@ "prettier" ], "rules": { + "testing-library/no-dom-import": "off", + "babel/new-cap": "off", "babel/quotes": "off" } } diff --git a/package.json b/package.json index 916d1b0..1a72961 100644 --- a/package.json +++ b/package.json @@ -31,7 +31,7 @@ "eslint": "^7.6.0", "eslint-config-prettier": "^6.11.0", "eslint-plugin-testcafe": "^0.2.1", - "kcd-scripts": "^6.0.0", + "kcd-scripts": "^7.2.1", "npm-run-all": "^4.1.5", "prettier": "^2.0.5", "semantic-release": "^17.0.7", diff --git a/src/index.ts b/src/index.ts index d200bc7..83eb4f7 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,3 +1,5 @@ +/* eslint-disable @typescript-eslint/no-implied-eval */ +/* eslint-disable no-new-func */ import { ClientFunction, Selector } from "testcafe"; import { Matcher, queries } from "@testing-library/dom"; import type { Options, QueryName, WithinSelectors } from "./types"; @@ -27,6 +29,7 @@ const withinSelectors = queryNames.reduce((acc, withinQueryName) => { )}.apply(null, args); `), }; + // eslint-disable-next-line }, {} as Record any>); export async function configureOnce(options: Partial) { @@ -46,10 +49,13 @@ const withWithinMethods = (selector: Selector) => { returnDOMNodes: true, }) as unknown) as WithinSelectors; }; +type SelectorArg = + | string + | Selector + | SelectorPromise + | (() => SelectorPromise); -export function within( - selector: string | Selector | SelectorPromise | (() => SelectorPromise) -): WithinSelectors { +export function within(selector: SelectorArg): WithinSelectors { if (selector instanceof Function) { return within(selector()); } @@ -65,7 +71,7 @@ export function within( } } -function isSelector(sel: any): sel is Selector { +function isSelector(sel: SelectorArg): sel is Selector { return sel.constructor.name === SELECTOR_TYPE; } diff --git a/tests/testcafe/.eslintrc b/tests/testcafe/.eslintrc new file mode 100644 index 0000000..66c3477 --- /dev/null +++ b/tests/testcafe/.eslintrc @@ -0,0 +1,8 @@ +{ + "plugins": ["testcafe"], + "extends": ["plugin:testcafe/recommended", "prettier"], + "rules": { + "@typescript-eslint/no-unused-expressions": "off", + "jest/no-done-callback": "off" + } +} diff --git a/tests/testcafe/configure.ts b/tests/testcafe/configure.ts index f14c1f7..be065da 100644 --- a/tests/testcafe/configure.ts +++ b/tests/testcafe/configure.ts @@ -1,22 +1,22 @@ -import { configure, configureOnce, getByTestId, getByText } from "../../src"; +import { configure, configureOnce, screen } from "../../src"; fixture`configure`.clientScripts( configure({ testIdAttribute: "data-automation-id" }) ).page`../../test-app/index.html`; test("supports alternative testIdAttribute", async (t) => { - await t.click(getByTestId("image-with-random-alt-tag")); + await t.click(screen.getByTestId("image-with-random-alt-tag")); }); test("still works after browser page load", async (t) => { await t - .click(getByText("Go to Page 2")) - .click(getByTestId("page2-thing")) - .expect(getByText("second page").exists) + .click(screen.getByText("Go to Page 2")) + .click(screen.getByTestId("page2-thing")) + .expect(screen.getByText("second page").exists) .ok(); }); test("can be used standalone", async (t) => { await configureOnce({ testIdAttribute: "data-other-test-id" }); - await t.click(getByTestId("other-id")); + await t.click(screen.getByTestId("other-id")); }); diff --git a/tests/testcafe/selectors.ts b/tests/testcafe/selectors.ts index 5f637a6..09f4f00 100644 --- a/tests/testcafe/selectors.ts +++ b/tests/testcafe/selectors.ts @@ -1,3 +1,4 @@ +/* eslint-disable testing-library/prefer-screen-queries */ import { getByText, getByPlaceholderText, @@ -73,13 +74,3 @@ test("still works after reload", async (t) => { await t.eval(() => location.reload(true)); await t.expect(getByText("getByText").exists).ok(); }); - -test.skip("getByTestId only throws the error message", async (t) => { - const testId = "Some random id"; - const errorMessage = `Unable to find an element by: [data-testid="${testId}"]`; - try { - await t.click(getByText(testId)); - } catch (e) { - await t.expect(e).contains(errorMessage); - } -}); diff --git a/tests/testcafe/within.ts b/tests/testcafe/within.ts index 3470377..70f2a6d 100644 --- a/tests/testcafe/within.ts +++ b/tests/testcafe/within.ts @@ -1,3 +1,5 @@ +/* eslint-disable testing-library/prefer-screen-queries */ +/* eslint-disable @typescript-eslint/await-thenable */ import { Selector } from "testcafe"; import { within, screen } from "../../src"; @@ -65,6 +67,7 @@ test('works with nested selector from "All" query with index - exact:false', asy test('works with nested selector from "All" query with index - function', async (t) => { const nestedDivs = screen.getAllByTestId((_content, element) => + // eslint-disable-next-line @typescript-eslint/no-non-null-assertion element.getAttribute("data-testid")!.startsWith("nested") ); await t.expect(nestedDivs.count).eql(2); @@ -82,8 +85,10 @@ test("works on a standard testcafe nested selector", async (t) => { test("should throw if invalid param", async (t) => { let didThrow = false; try { - // @ts-ignore + // eslint-disable-next-line @typescript-eslint/ban-ts-comment + // @ts-expect-error await t.expect(within({ foo: "bar" }).getByText("baz").exists).ok(); + // eslint-disable-next-line @typescript-eslint/no-implicit-any-catch } catch (e) { didThrow = true; } @@ -97,6 +102,7 @@ test("should throw error if count > 1", async (t) => { let didThrow = false; try { await t.expect(within(nestedDivs).getByText("blah").exists); + // eslint-disable-next-line @typescript-eslint/no-implicit-any-catch } catch (e) { didThrow = true; } diff --git a/tests/unit/selectors.test.ts b/tests/unit/selectors.test.ts index bd001a3..539f9f0 100644 --- a/tests/unit/selectors.test.ts +++ b/tests/unit/selectors.test.ts @@ -1,5 +1,5 @@ -import * as allExports from "../../src"; import { queries } from "@testing-library/dom"; +import * as allExports from "../../src"; it("exports expected exports", () => { expect(allExports).toMatchObject(expect.any(Object)); @@ -20,7 +20,7 @@ it("exports expected exports", () => { }); it("exports all dom-testing-library queries", () => { - let { + const { configureOnce, configure, within,