Jest-dom: new matcher: toHaveAria

Created on 31 Jan 2020  路  3Comments  路  Source: testing-library/jest-dom

Describe the feature you'd like:

seems like a pretty common pattern to use expect(element).toHaveAttribute("aria-xxx", 'foo') so thought maybe it would be nice to have a matcher just for aria: expect(element).toHaveAria("xxx", "foo")

it's mostly syntactical sugar, but just thought I'd see what folks think.

Suggested implementation:

could just be a simple wrapper around toHaveAttribute()

Describe alternatives you've considered:

Teachability, Documentation, Adoption, Migration Strategy:

enhancement needs discussion

Most helpful comment

I think we should stick with the purpose of the lib.

In general, the overall criteria for what is considered a useful custom matcher to add to this library, is that doing the equivalent assertion on our own makes the test code more verbose, less clear in its intent, and/or harder to read.

All 3 comments

I'm not a fan of increasing API surface i.e. adding more choices. Now users would have to decide: "Do I use toHaveAttribute or toHaveAria, and what is the difference?"

I think we should stick with the purpose of the lib.

In general, the overall criteria for what is considered a useful custom matcher to add to this library, is that doing the equivalent assertion on our own makes the test code more verbose, less clear in its intent, and/or harder to read.

I echo @eps1lon and @lourenci. As the proposal even acknowledges, it's mostly syntactic sugar. The equivalent assertion with .toHaveAttribute is simple enough.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

alexandernanberg picture alexandernanberg  路  4Comments

lukaszfiszer picture lukaszfiszer  路  6Comments

BurntCaramel picture BurntCaramel  路  5Comments

gnapse picture gnapse  路  3Comments

srittau picture srittau  路  5Comments