Skip to content

[good first issue] Add "have.length" assertion #216

@kevinccbsg

Description

@kevinccbsg

Common need (assert list/result counts). Missing from the current assertion set.

Scope

  • Add the have.length case in src/asserts/index.ts (positive + negative messages, and the case in the switch). Accept a number as the expected length.
  • Works on a single element against el.children.length. If a collection variant is desired, leave a TODO for a follow-up.
  • Add a unit test in src/tests/asserts/.
  • Add a row in docs/api/assertions.md.
  • Add a small list in examples/twd-test-app/src/pages/Assertions.tsx with data-testid="have-length" and a sample in assertion-examples.twd.test.ts using screenDom.getByTestId(...) + twd.should(el, "have.length", 3).

Reference

  • Mirror the have.class implementation.
  • Query pattern: examples/twd-test-app/src/twd-tests/screen-queries.twd.test.ts.

Acceptance criteria

  • npm run test:ci is green.
  • The new example test runs green in the TWD sidebar of twd-test-app.
  • docs/api/assertions.md updated.
  • PR includes a screenshot of the sidebar.

How to contribute

Read CONTRIBUTING.md first. Quick steps for this issue:

  1. Fork, clone, create a feature branch: git checkout -b feat/have-length-assertion.
  2. From the repo root, build the library and sync it to the example apps:
    npm install
    npm run build
    npm run copy:mock-sw
  3. Install and run the test app:
    cd examples/twd-test-app
    npm install
    npm run dev
  4. Open the app in the browser — the TWD sidebar appears on the right. Run your new tests from the sidebar and confirm they pass.
  5. Run the library's unit tests from the repo root: npm run test:ci.
  6. 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    documentationImprovements or additions to documentationenhancementNew feature or requestgood first issueGood for newcomers

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions