Skip to content

Commit 5c71562

Browse files
chore(deps-dev): bump kcd-scripts from 6.7.0 to 7.2.1 (#265)
Co-authored-by: dependabot-preview[bot] <27856297+dependabot-preview[bot]@users.noreply.github.com> Co-authored-by: Ben Monro <ben.monro@gmail.com>
1 parent 3121563 commit 5c71562

File tree

8 files changed

+37
-24
lines changed

8 files changed

+37
-24
lines changed

.eslintrc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
"prettier"
77
],
88
"rules": {
9+
"testing-library/no-dom-import": "off",
10+
"babel/new-cap": "off",
911
"babel/quotes": "off"
1012
}
1113
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
"eslint": "^7.6.0",
3232
"eslint-config-prettier": "^6.11.0",
3333
"eslint-plugin-testcafe": "^0.2.1",
34-
"kcd-scripts": "^6.0.0",
34+
"kcd-scripts": "^7.2.1",
3535
"npm-run-all": "^4.1.5",
3636
"prettier": "^2.0.5",
3737
"semantic-release": "^17.0.7",

src/index.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
/* eslint-disable @typescript-eslint/no-implied-eval */
2+
/* eslint-disable no-new-func */
13
import { ClientFunction, Selector } from "testcafe";
24
import { Matcher, queries } from "@testing-library/dom";
35
import type { Options, QueryName, WithinSelectors } from "./types";
@@ -27,6 +29,7 @@ const withinSelectors = queryNames.reduce((acc, withinQueryName) => {
2729
)}.apply(null, args);
2830
`),
2931
};
32+
// eslint-disable-next-line
3033
}, {} as Record<QueryName, (node: Element, ...methodParams: any[]) => any>);
3134

3235
export async function configureOnce(options: Partial<Options>) {
@@ -46,10 +49,13 @@ const withWithinMethods = (selector: Selector) => {
4649
returnDOMNodes: true,
4750
}) as unknown) as WithinSelectors;
4851
};
52+
type SelectorArg =
53+
| string
54+
| Selector
55+
| SelectorPromise
56+
| (() => SelectorPromise);
4957

50-
export function within(
51-
selector: string | Selector | SelectorPromise | (() => SelectorPromise)
52-
): WithinSelectors {
58+
export function within(selector: SelectorArg): WithinSelectors {
5359
if (selector instanceof Function) {
5460
return within(selector());
5561
}
@@ -65,7 +71,7 @@ export function within(
6571
}
6672
}
6773

68-
function isSelector(sel: any): sel is Selector {
74+
function isSelector(sel: SelectorArg): sel is Selector {
6975
return sel.constructor.name === SELECTOR_TYPE;
7076
}
7177

tests/testcafe/.eslintrc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"plugins": ["testcafe"],
3+
"extends": ["plugin:testcafe/recommended", "prettier"],
4+
"rules": {
5+
"@typescript-eslint/no-unused-expressions": "off",
6+
"jest/no-done-callback": "off"
7+
}
8+
}

tests/testcafe/configure.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
1-
import { configure, configureOnce, getByTestId, getByText } from "../../src";
1+
import { configure, configureOnce, screen } from "../../src";
22

33
fixture`configure`.clientScripts(
44
configure({ testIdAttribute: "data-automation-id" })
55
).page`../../test-app/index.html`;
66

77
test("supports alternative testIdAttribute", async (t) => {
8-
await t.click(getByTestId("image-with-random-alt-tag"));
8+
await t.click(screen.getByTestId("image-with-random-alt-tag"));
99
});
1010

1111
test("still works after browser page load", async (t) => {
1212
await t
13-
.click(getByText("Go to Page 2"))
14-
.click(getByTestId("page2-thing"))
15-
.expect(getByText("second page").exists)
13+
.click(screen.getByText("Go to Page 2"))
14+
.click(screen.getByTestId("page2-thing"))
15+
.expect(screen.getByText("second page").exists)
1616
.ok();
1717
});
1818

1919
test("can be used standalone", async (t) => {
2020
await configureOnce({ testIdAttribute: "data-other-test-id" });
21-
await t.click(getByTestId("other-id"));
21+
await t.click(screen.getByTestId("other-id"));
2222
});

tests/testcafe/selectors.ts

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* eslint-disable testing-library/prefer-screen-queries */
12
import {
23
getByText,
34
getByPlaceholderText,
@@ -73,13 +74,3 @@ test("still works after reload", async (t) => {
7374
await t.eval(() => location.reload(true));
7475
await t.expect(getByText("getByText").exists).ok();
7576
});
76-
77-
test.skip("getByTestId only throws the error message", async (t) => {
78-
const testId = "Some random id";
79-
const errorMessage = `Unable to find an element by: [data-testid="${testId}"]`;
80-
try {
81-
await t.click(getByText(testId));
82-
} catch (e) {
83-
await t.expect(e).contains(errorMessage);
84-
}
85-
});

tests/testcafe/within.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
/* eslint-disable testing-library/prefer-screen-queries */
2+
/* eslint-disable @typescript-eslint/await-thenable */
13
import { Selector } from "testcafe";
24
import { within, screen } from "../../src";
35

@@ -65,6 +67,7 @@ test('works with nested selector from "All" query with index - exact:false', asy
6567

6668
test('works with nested selector from "All" query with index - function', async (t) => {
6769
const nestedDivs = screen.getAllByTestId((_content, element) =>
70+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
6871
element.getAttribute("data-testid")!.startsWith("nested")
6972
);
7073
await t.expect(nestedDivs.count).eql(2);
@@ -82,8 +85,10 @@ test("works on a standard testcafe nested selector", async (t) => {
8285
test("should throw if invalid param", async (t) => {
8386
let didThrow = false;
8487
try {
85-
// @ts-ignore
88+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
89+
// @ts-expect-error
8690
await t.expect(within({ foo: "bar" }).getByText("baz").exists).ok();
91+
// eslint-disable-next-line @typescript-eslint/no-implicit-any-catch
8792
} catch (e) {
8893
didThrow = true;
8994
}
@@ -97,6 +102,7 @@ test("should throw error if count > 1", async (t) => {
97102
let didThrow = false;
98103
try {
99104
await t.expect(within(nestedDivs).getByText("blah").exists);
105+
// eslint-disable-next-line @typescript-eslint/no-implicit-any-catch
100106
} catch (e) {
101107
didThrow = true;
102108
}

tests/unit/selectors.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import * as allExports from "../../src";
21
import { queries } from "@testing-library/dom";
2+
import * as allExports from "../../src";
33

44
it("exports expected exports", () => {
55
expect(allExports).toMatchObject(expect.any(Object));
@@ -20,7 +20,7 @@ it("exports expected exports", () => {
2020
});
2121

2222
it("exports all dom-testing-library queries", () => {
23-
let {
23+
const {
2424
configureOnce,
2525
configure,
2626
within,

0 commit comments

Comments
 (0)