qunit-dom
qunit-dom copied to clipboard
Not possible to have both value and message be optional for hasAttribute assertion
The type signature of hasAttribute
lists both value
and message
as optional however this isn't possible to pull off in TypesScript as passing a message string as the second argument means that the message string is interpreted as the value string.
https://github.com/simplabs/qunit-dom/blob/08cedfad10c8ab7fbb3c800b59d91d18f64a11ae/lib/assertions.ts#L300
It is not currently clear how to write an assertion to only check the attribute's existence and not it's value but also include a message.
From reading the code the object
referred to in the documentation is the object { any: true }
which seems to accomplish what I want but it feels like an internal implementation detail of the library.
I've ended up writing my tests like this
assert.dom('.bar').hasAttribute('data-test-foo', { any: true }, 'My assertion message');
@houli that is the correct solution for now, yes. For hasText()
we had a similar issue and decided to introduce a hasAnyText()
assertion which essentially just calls hasText()
with { any: true }
. I guess we missed that for hasAttribute()
, but I'm open to PRs that add it :)
@Turbo87 how about adding an assertion called hasAttributeAnyValue()
that basically calls hasAttribute
with { any: true }
?