@thisisagile/easy-test-react 12.7.0 → 12.7.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/Tester.d.ts +5 -5
- package/dist/Tester.js +5 -5
- package/dist/Tester.js.map +1 -1
- package/package.json +3 -3
- package/src/Tester.ts +20 -19
package/dist/Tester.d.ts
CHANGED
|
@@ -6,15 +6,15 @@ export declare class Tester {
|
|
|
6
6
|
constructor(container: HTMLElement);
|
|
7
7
|
static render: (component: ReactElement) => Promise<Tester>;
|
|
8
8
|
static renderSync: (component: ReactElement) => Tester;
|
|
9
|
-
byText: (text: string) => HTMLElement;
|
|
9
|
+
byText: (text: string, index?: number) => HTMLElement;
|
|
10
10
|
atText: (text: string) => ElementTester;
|
|
11
|
-
byId: (id: Id) => HTMLElement;
|
|
11
|
+
byId: (id: Id, index?: number) => HTMLElement;
|
|
12
12
|
atId: (id: Id) => ElementTester;
|
|
13
|
-
byRole: (role: string) => HTMLElement;
|
|
13
|
+
byRole: (role: string, index?: number) => HTMLElement;
|
|
14
14
|
atRole: (role: string) => ElementTester;
|
|
15
|
-
byTitle: (title: string) => HTMLElement;
|
|
15
|
+
byTitle: (title: string, index?: number) => HTMLElement;
|
|
16
16
|
atTitle: (title: string) => ElementTester;
|
|
17
|
-
byPlaceholder: (placeholder: string) => HTMLElement;
|
|
17
|
+
byPlaceholder: (placeholder: string, index?: number) => HTMLElement;
|
|
18
18
|
atPlaceholder: (placeholder: string) => ElementTester;
|
|
19
19
|
submit: (id?: Id) => ElementTester;
|
|
20
20
|
}
|
package/dist/Tester.js
CHANGED
|
@@ -7,15 +7,15 @@ const ElementTester_1 = require("./ElementTester");
|
|
|
7
7
|
class Tester {
|
|
8
8
|
constructor(container) {
|
|
9
9
|
this.container = container;
|
|
10
|
-
this.byText = (text) => react_1.screen.getByText(text);
|
|
10
|
+
this.byText = (text, index) => index ? react_1.screen.getAllByText(text)[index] : react_1.screen.getByText(text);
|
|
11
11
|
this.atText = (text) => new ElementTester_1.ElementTester(() => this.byText(text));
|
|
12
|
-
this.byId = (id) => react_1.screen.getByTestId(id.toString());
|
|
12
|
+
this.byId = (id, index) => index ? react_1.screen.getAllByTestId(id.toString())[index] : react_1.screen.getByTestId(id.toString());
|
|
13
13
|
this.atId = (id) => new ElementTester_1.ElementTester(() => this.byId(id));
|
|
14
|
-
this.byRole = (role) => react_1.screen.getByRole(role);
|
|
14
|
+
this.byRole = (role, index) => index ? react_1.screen.getAllByRole(role)[index] : react_1.screen.getByRole(role);
|
|
15
15
|
this.atRole = (role) => new ElementTester_1.ElementTester(() => this.byRole(role));
|
|
16
|
-
this.byTitle = (title) => react_1.screen.getByTitle(title);
|
|
16
|
+
this.byTitle = (title, index) => index ? react_1.screen.getAllByTitle(title)[index] : react_1.screen.getByTitle(title);
|
|
17
17
|
this.atTitle = (title) => new ElementTester_1.ElementTester(() => this.byTitle(title));
|
|
18
|
-
this.byPlaceholder = (placeholder) => react_1.screen.getByPlaceholderText(placeholder);
|
|
18
|
+
this.byPlaceholder = (placeholder, index) => index ? react_1.screen.getAllByPlaceholderText(placeholder)[index] : react_1.screen.getByPlaceholderText(placeholder);
|
|
19
19
|
this.atPlaceholder = (placeholder) => new ElementTester_1.ElementTester(() => this.byPlaceholder(placeholder));
|
|
20
20
|
this.submit = (id = 'btn-submit') => this.atId(id);
|
|
21
21
|
}
|
package/dist/Tester.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Tester.js","sourceRoot":"","sources":["../src/Tester.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"Tester.js","sourceRoot":"","sources":["../src/Tester.ts"],"names":[],"mappings":";;;AAAA,kDAAsD;AAGtD,mDAA8C;AAC9C,mDAA8C;AAE9C,MAAa,MAAM;IACf,YAA4B,SAAsB;QAAtB,cAAS,GAAT,SAAS,CAAa;QAMlD,WAAM,GAAG,CAAC,IAAY,EAAE,KAAc,EAAe,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"version": "12.7.
|
|
3
|
+
"version": "12.7.8",
|
|
4
4
|
"description": "Straightforward wrapper library for testing-library/react",
|
|
5
5
|
"author": "Sander Hoogendoorn",
|
|
6
6
|
"license": "MIT",
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
"access": "public"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
|
-
"@thisisagile/easy-test": "12.7.
|
|
36
|
+
"@thisisagile/easy-test": "12.7.8",
|
|
37
37
|
"jest-environment-jsdom": "^29.0.3",
|
|
38
38
|
"weak-napi": "^2.0.2"
|
|
39
39
|
},
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
"@testing-library/dom": "^8.18.1",
|
|
42
42
|
"@testing-library/jest-dom": "^5.16.5",
|
|
43
43
|
"@testing-library/react": "^13.4.0",
|
|
44
|
-
"@thisisagile/easy": "^12.7.
|
|
44
|
+
"@thisisagile/easy": "^12.7.8",
|
|
45
45
|
"@types/react": "^18.0.24",
|
|
46
46
|
"react": "^18.2.0",
|
|
47
47
|
"react-dom": "^18.2.0"
|
package/src/Tester.ts
CHANGED
|
@@ -1,26 +1,27 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
1
|
+
import {render, screen} from '@testing-library/react';
|
|
2
|
+
import {ReactElement} from 'react';
|
|
3
|
+
import {Id} from '@thisisagile/easy';
|
|
4
|
+
import {waitForRender} from './waitForRender';
|
|
5
|
+
import {ElementTester} from './ElementTester';
|
|
6
6
|
|
|
7
7
|
export class Tester {
|
|
8
|
-
|
|
8
|
+
constructor(public readonly container: HTMLElement) {
|
|
9
|
+
}
|
|
9
10
|
|
|
10
|
-
|
|
11
|
-
|
|
11
|
+
static render = (component: ReactElement): Promise<Tester> => waitForRender(component).then(c => new Tester(c.container));
|
|
12
|
+
static renderSync = (component: ReactElement): Tester => new Tester(render(component).container);
|
|
12
13
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
14
|
+
byText = (text: string, index?: number): HTMLElement => index ? screen.getAllByText(text)[index] : screen.getByText(text);
|
|
15
|
+
atText = (text: string): ElementTester => new ElementTester(() => this.byText(text));
|
|
16
|
+
byId = (id: Id, index?: number): HTMLElement => index ? screen.getAllByTestId(id.toString())[index] : screen.getByTestId(id.toString());
|
|
17
|
+
atId = (id: Id): ElementTester => new ElementTester(() => this.byId(id));
|
|
18
|
+
byRole = (role: string, index?: number): HTMLElement => index ? screen.getAllByRole(role)[index] : screen.getByRole(role);
|
|
19
|
+
atRole = (role: string): ElementTester => new ElementTester(() => this.byRole(role));
|
|
20
|
+
byTitle = (title: string, index?: number): HTMLElement => index ? screen.getAllByTitle(title)[index] : screen.getByTitle(title);
|
|
21
|
+
atTitle = (title: string): ElementTester => new ElementTester(() => this.byTitle(title));
|
|
22
|
+
byPlaceholder = (placeholder: string, index?: number): HTMLElement => index ? screen.getAllByPlaceholderText(placeholder)[index] : screen.getByPlaceholderText(placeholder);
|
|
23
|
+
atPlaceholder = (placeholder: string): ElementTester => new ElementTester(() => this.byPlaceholder(placeholder));
|
|
24
|
+
submit = (id: Id = 'btn-submit'): ElementTester => this.atId(id);
|
|
24
25
|
}
|
|
25
26
|
|
|
26
27
|
export const rendersWait = async (component: ReactElement): Promise<Tester> => await Tester.render(component);
|