Loading...
Loading...
TWD test agent — writes, runs, and validates in-browser tests while you develop. Automatically invoked when writing or modifying tests, or when verifying features work correctly.
npx skill4agent add brikev/twd twd-tester*.twd.test.tsnpx twd-relay runimport { twd, userEvent, screenDom } from "twd-js";
import { describe, it, beforeEach, afterEach, expect } from "twd-js/runner";describeitbeforeEachexpecttwd-js/runner*.twd.test.ts.tsxtwd.get()twd.getAll()userEvent.*screenDom.findBy*twd.visit()twd.waitForRequest()// By role (RECOMMENDED)
screenDom.getByRole("button", { name: /submit/i });
screenDom.getByRole("heading", { level: 2, name: "Title" });
// By label (form inputs)
screenDom.getByLabelText(/email/i);
// By text
screenDom.getByText(/no items/i);
// Async variants (wait for element to appear)
await screenDom.findByRole("heading", { name: "Title" }, { timeout: 3000 });
// CSS selector fallback (returns twd element)
const el = await twd.get(".custom-container");await userEvent.type(input, "text value");
await userEvent.clear(input);
await userEvent.click(button);
await userEvent.selectOptions(select, "value");
await userEvent.keyboard("{Enter}");await twd.visit("/some-page");
await twd.wait(100); // ms delay// Function style (use with screenDom elements)
twd.should(element, "be.visible");
twd.should(element, "have.text", "Exact Text");
twd.should(element, "contain.text", "partial");
twd.should(element, "have.attr", "aria-selected", "true");
twd.should(element, "have.value", "test@example.com");
twd.should(element, "be.disabled");
twd.should(element, "be.checked");
// Method style (use with twd.get() elements)
const el = await twd.get(".item");
el.should("have.text", "Hello");
// URL assertions
await twd.url().should("contain.url", "/dashboard");
// Chai expect (non-element assertions)
expect(array).to.have.length(3);
expect(request.request).to.deep.equal({ key: "value" });twd.visit()await twd.mockRequest("uniqueLabel", {
url: "/api/some-endpoint",
method: "GET",
response: mockData,
status: 200,
});
// With regex URL matching
await twd.mockRequest("search", {
url: "/api/users\\?.*",
method: "GET",
response: results,
status: 200,
urlRegex: true,
});
// Wait for request and verify payload
const req = await twd.waitForRequest("createItem");
expect(req.request).to.deep.equal({ field: "value" });
// Clear all mocks (in beforeEach)
twd.clearRequestMockRules();import Sinon from "sinon";
import authModule from "../hooks/useAuth";
Sinon.stub(authModule, "useAuth").returns({ isAuthenticated: true });
// Cleanup: Sinon.restore() in beforeEachimport { screenDom, twd, userEvent } from "twd-js";
import { beforeEach, describe, it, expect } from "twd-js/runner";
describe("Feature name", () => {
beforeEach(() => {
twd.clearRequestMockRules();
twd.clearComponentMocks();
});
it("should display the page correctly", async () => {
await twd.mockRequest("getData", {
method: "GET",
url: "/api/endpoint",
response: { items: [{ id: 1, name: "Item" }] },
status: 200,
});
await twd.visit("/route");
const heading = await screenDom.findByRole(
"heading",
{ name: "Page Title" },
{ timeout: 3000 },
);
twd.should(heading, "be.visible");
});
});npx twd-relay runawaittwd.visit()twd.clearRequestMockRules()beforeEachfspathdescribe/it/beforeEachtwd-js/runnernpx twd-relay run