Skip to content

add toHaveCount assertion for playwright locator #8510

@jnizet

Description

@jnizet

Clear and concise description of the problem

To test that a locator matches a given number of elements, in polling mode, we currently have to do (unless I'm mistaken)

await expect.poll(() => locator.elements().length).toBe(3);

I think that kind of assertion is quite frequent, and Playwright hass a toHaveCount()assertion: https://playwright.dev/docs/api/class-locatorassertions#locator-assertions-to-have-count

Suggested solution

Introduce a similar toHaveCount assertion in vitest, so that we can instead write

await expect.element(locator).toHaveCount(3);

Alternative

No response

Additional context

No response

Validations

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions