@@ -109,21 +109,35 @@ pnpm add twd-js
109109
110110 ``` ts
111111 // src/app.twd.test.ts
112- import { twd , userEvent } from " twd-js" ;
112+ import { twd , userEvent , screenDom } from " twd-js" ;
113113 import { describe , it } from " twd-js/runner" ;
114114
115115 describe (" Hello World Page" , () => {
116116 it (" should display the welcome title and counter button" , async () => {
117117 await twd .visit (" /" );
118118
119- const title = await twd .get (" [data-testid='welcome-title']" );
119+ // Option 1: Use TWD's native selectors
120+ const title = await twd .get (" h1" );
120121 title .should (" be.visible" ).should (" have.text" , " Welcome to TWD" );
121122
122- const counterButton = await twd .get (" [data-testid='counter- button'] " );
123+ const counterButton = await twd .get (" button" );
123124 counterButton .should (" be.visible" ).should (" have.text" , " Count is 0" );
124125
125- await userEvent .click (counterButton .el );
126+ const user = userEvent .setup ();
127+ await user .click (counterButton .el );
126128 counterButton .should (" have.text" , " Count is 1" );
129+
130+ // Option 2: Use Testing Library queries (semantic, accessible)
131+ // const title = screenDom.getByRole("heading", { name: /welcome to twd/i });
132+ // twd.should(title, "be.visible");
133+ // twd.should(title, "have.text", "Welcome to TWD");
134+ //
135+ // const counterButton = screenDom.getByRole("button", { name: /count is/i });
136+ // twd.should(counterButton, "be.visible");
137+ // twd.should(counterButton, "have.text", "Count is 0");
138+ //
139+ // await user.click(counterButton);
140+ // twd.should(counterButton, "have.text", "Count is 1");
127141 });
128142 });
129143 ```
@@ -216,8 +230,9 @@ describe("User authentication", () => {
216230
217231### Element Selection
218232
219- TWD provides two main methods for selecting elements :
233+ TWD provides multiple ways to select elements :
220234
235+ ** TWD Native Selectors :**
221236` ` ` ts
222237// Select a single element
223238const button = await twd.get("button");
@@ -228,6 +243,22 @@ const items = await twd.getAll(".item");
228243items[0].should("be.visible");
229244` ` `
230245
246+ ** Testing Library Queries (also supported ):**
247+ ` ` ` ts
248+ import { screenDom, twd } from "twd-js";
249+
250+ // Semantic, accessible queries
251+ const button = screenDom.getByRole("button", { name: /submit/i });
252+ const input = screenDom.getByLabelText("Email:");
253+ const heading = screenDom.getByRole("heading", { name: "Welcome" });
254+
255+ // Use twd.should() for assertions (not .should() method)
256+ twd.should(button, "be.visible");
257+ twd.should(input, "have.value", "user@example.com");
258+ ` ` `
259+
260+ Both approaches work together seamlessly . See the [Testing Library docs ](/ api / react - testing - library ) for more details .
261+
231262### Assertions
232263
233264TWD includes a comprehensive set of assertions for testing element states :
@@ -265,21 +296,21 @@ twd.url().should("contain.url", "/contact");
265296TWD integrates with ` @testing-library/user-event ` for realistic user interactions :
266297
267298` ` ` ts
268- import { userEvent } from "twd-js";
299+ import { userEvent, screenDom } from "twd-js";
269300
270301const user = userEvent.setup();
271- const button = await twd.get("button");
272- const input = await twd.get("input");
273302
274- // Click interactions
303+ // With TWD selectors
304+ const button = await twd.get("button");
275305await user.click(button.el);
276- await user.dblClick(button.el);
277306
278- // Typing
279- await user.type(input.el, "Hello World");
307+ // With React Testing Library queries
308+ const input = screenDom.getByLabelText("Email:");
309+ await user.type(input, "user@example.com");
280310
281311// Form interactions
282- await user.selectOptions(selectElement.el, "option-value");
312+ const select = screenDom.getByRole("combobox");
313+ await user.selectOptions(select, "option-value");
283314` ` `
284315
285316## API Mocking
@@ -323,7 +354,7 @@ This plugin will automatically remove `mock-sw.js` from your build output during
323354Use ` twd.mockRequest() ` to define API mocks in your tests :
324355
325356` ` ` ts
326- import { twd } from "twd-js";
357+ import { twd, screenDom, userEvent } from "twd-js";
327358
328359// Initialize mocking when loading tests
329360// await twd.initRequestMocking();
@@ -343,8 +374,9 @@ it("fetches user data", async () => {
343374 });
344375
345376 // Trigger the request in your app
346- const button = await twd.get("button[data-testid='load-user']");
347- await userEvent.click(button.el);
377+ const button = screenDom.getByRole("button", { name: /load user/i });
378+ const user = userEvent.setup();
379+ await user.click(button);
348380
349381 // Wait for the mock to be called
350382 const rule = await twd.waitForRequest("getUser");
@@ -391,7 +423,10 @@ console.log("Response:", rule.response);
391423| ` twd.getAll(selector) ` | Select multiple elements | ` await twd.getAll(".item") ` |
392424| ` twd.visit(url) ` | Navigate to URL | ` twd.visit("/contact") ` |
393425| ` twd.wait(ms) ` | Wait for specified time | ` await twd.wait(500) ` |
426+ | ` twd.should(el, assertion, ...args) ` | Assert on any element | ` twd.should(button, "be.visible") ` |
394427| ` twd.url() ` | Get URL API for assertions | ` twd.url().should("contain.url", "/home") ` |
428+ | ` screenDom ` | Testing Library queries | ` screenDom.getByRole("button") ` |
429+ | ` userEvent ` | User interaction library | ` userEvent.setup().click(element) ` |
395430
396431### Assertions
397432
0 commit comments