Exercises twd.mockRequest() — a core feature — in a realistic paged-list scenario.
Scope
- New page
examples/twd-test-app/src/pages/Pagination.tsx:
- Fetches a paged list (e.g.
/api/items?page=N).
- Next / Prev buttons.
- A current-page label.
- Next disabled on last page, Prev disabled on page 1.
- Register the route in
routes.tsx and add a link from the App menu.
- New test file
examples/twd-test-app/src/twd-tests/pagination.twd.test.ts:
- Page 1 loads (mocked request) → assert items render.
- Click Next (mocked page 2) → assert updated items.
- Prev is disabled on page 1; Next is disabled on the last page.
- All queries via
screenDom.getByRole("button", { name: /next/i }), screenDom.getAllByRole("listitem"), etc.
Reference
examples/twd-test-app/src/pages/LoadShows.tsx + load-shows.twd.test.ts (already uses request mocking).
Acceptance criteria
How to contribute
Read CONTRIBUTING.md first. Quick steps for this issue:
- Fork, clone, create a feature branch:
git checkout -b feat/pagination-example.
- From the repo root, build the library and sync it to the example apps:
npm install
npm run build
npm run copy:mock-sw
- Install and run the test app:
cd examples/twd-test-app
npm install
npm run dev
- Open the app in the browser — the TWD sidebar appears on the right. Run your new tests from the sidebar and confirm they pass.
- Run the library's unit tests from the repo root:
npm run test:ci.
- Open the PR with screenshots of the sidebar showing green tests.
Always prefer screenDom (Testing Library) for element queries. Avoid twd.get() in new code.
Exercises
twd.mockRequest()— a core feature — in a realistic paged-list scenario.Scope
examples/twd-test-app/src/pages/Pagination.tsx:/api/items?page=N).routes.tsxand add a link from the App menu.examples/twd-test-app/src/twd-tests/pagination.twd.test.ts:screenDom.getByRole("button", { name: /next/i }),screenDom.getAllByRole("listitem"), etc.Reference
examples/twd-test-app/src/pages/LoadShows.tsx+load-shows.twd.test.ts(already uses request mocking).Acceptance criteria
docs/api-mocking.mdpointing at this example.How to contribute
Read CONTRIBUTING.md first. Quick steps for this issue:
git checkout -b feat/pagination-example.cd examples/twd-test-app npm install npm run devnpm run test:ci.