Skip to content

Commit 28d7cfb

Browse files
authored
feat: add screen export to mirror testing-lib (#174)
1 parent 7085d5d commit 28d7cfb

File tree

5 files changed

+96
-7
lines changed

5 files changed

+96
-7
lines changed

src/index.ts

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,4 +133,55 @@ export const queryAllByTestId = bindFunction("queryAllByTestId");
133133
export const findByTestId = bindFunction("findByTestId");
134134
export const findAllByTestId = bindFunction("findAllByTestId");
135135

136+
export const screen = {
137+
getByLabelText,
138+
getAllByLabelText,
139+
queryByLabelText,
140+
queryAllByLabelText,
141+
findByLabelText,
142+
findAllByLabelText,
143+
getByText,
144+
getAllByText,
145+
queryByText,
146+
queryAllByText,
147+
findByText,
148+
findAllByText,
149+
getByAltText,
150+
getByPlaceholderText,
151+
getAllByPlaceholderText,
152+
queryByPlaceholderText,
153+
queryAllByPlaceholderText,
154+
findByPlaceholderText,
155+
findAllByPlaceholderText,
156+
getAllByAltText,
157+
queryByAltText,
158+
queryAllByAltText,
159+
findByAltText,
160+
findAllByAltText,
161+
getByTitle,
162+
getAllByTitle,
163+
queryByTitle,
164+
queryAllByTitle,
165+
findByTitle,
166+
findAllByTitle,
167+
getByDisplayValue,
168+
getAllByDisplayValue,
169+
queryByDisplayValue,
170+
queryAllByDisplayValue,
171+
findByDisplayValue,
172+
getByRole,
173+
getAllByRole,
174+
queryByRole,
175+
queryAllByRole,
176+
findByRole,
177+
findAllByRole,
178+
findAllByDisplayValue,
179+
getByTestId,
180+
getAllByTestId,
181+
queryByTestId,
182+
queryAllByTestId,
183+
findByTestId,
184+
findAllByTestId,
185+
};
186+
136187
export * from "./types";

src/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Config, BoundFunction } from "@testing-library/dom";
1+
import { Config, BoundFunction, queries } from "@testing-library/dom";
22

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

tests/testcafe/screen.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { screen } from "../../src";
2+
3+
fixture`screen`.page`../../test-app/index.html`;
4+
5+
test("getByPlaceHolderText", async (t) => {
6+
await t.typeText(
7+
screen.getByPlaceholderText("Placeholder Text"),
8+
"Hello Placeholder"
9+
);
10+
});
11+
12+
test("getByText", async (t) => {
13+
await t.click(screen.getByText("getByText"));
14+
});
15+
16+
test("getByLabelText", async (t) => {
17+
await t.typeText(
18+
screen.getByLabelText("Label For Input Labelled By Id"),
19+
"Hello Input Labelled By Id"
20+
);
21+
});

tests/unit/__snapshots__/selectors.test.ts.snap

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

3-
exports[`exports expected selectors 1`] = `
3+
exports[`exports expected exports 1`] = `
44
Array [
55
"configureOnce",
66
"configure",
@@ -53,5 +53,6 @@ Array [
5353
"queryAllByTestId",
5454
"findByTestId",
5555
"findAllByTestId",
56+
"screen",
5657
]
5758
`;

tests/unit/selectors.test.ts

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

4-
it("exports expected selectors", () => {
5-
expect(selectors).toMatchObject(expect.any(Object));
6-
expect(Object.keys(selectors)).toMatchSnapshot();
4+
it("exports expected exports", () => {
5+
expect(allExports).toMatchObject(expect.any(Object));
6+
7+
expect(Object.keys(allExports)).toMatchSnapshot();
8+
9+
const { screen, ...selectors } = allExports;
10+
711
Object.keys(selectors).forEach((selector) => {
812
expect(selectors[selector as keyof typeof selectors]).toBeInstanceOf(
913
Function
1014
);
1115
});
16+
17+
Object.keys(screen).forEach((selector) => {
18+
expect(screen[selector as keyof typeof screen]).toBeInstanceOf(Function);
19+
});
1220
});
1321

1422
it("exports all dom-testing-library queries", () => {
15-
let { configureOnce, configure, within, ...justSelectors } = selectors;
23+
let {
24+
configureOnce,
25+
configure,
26+
within,
27+
screen,
28+
...justSelectors
29+
} = allExports;
1630
expect(Object.keys(justSelectors).sort()).toEqual(
1731
Object.keys(queries).sort()
1832
);
33+
34+
expect(Object.keys(screen).sort()).toEqual(Object.keys(queries).sort());
1935
});

0 commit comments

Comments
 (0)