Skip to content

Ability to iterate an Array of HTMLElement and expect similar properties #454

Open
@colpsi

Description

@colpsi

Describe the feature you'd like:

When using getAll* there should be an option to iterate through the returned array and expect a similar propertie on each component. Right now it works with a normal foreach but in my opinion this would make the test more readable.

Suggested implementation:

render(<div>
   <input aria-label="0" aria-invalid="true" aria-errormessage="form-error-message"/>
   <input aria-label="1" aria-invalid="true" aria-errormessage="form-error-message"/>
</div>
<p id="form-error-message">Invalid Form Input</p>)

expect(screen.getAllByRole("textbox")).foreach.toHaveErrorMessage("Invalid Form Input")

Describe alternatives you've considered:

render(<div>
   <input aria-label="0" aria-invalid="true" aria-errormessage="form-error-message"/>
   <input aria-label="1" aria-invalid="true" aria-errormessage="form-error-message"/>
</div>
<p id="form-error-message">Invalid Form Input</p>)
screen.getAllByRole("textbox").foreach(e => expect(e).toHaveErrorMessage("Invalid Form Input"))

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions