qunit-dom icon indicating copy to clipboard operation
qunit-dom copied to clipboard

Not possible to have both value and message be optional for hasAttribute assertion

Open houli opened this issue 5 years ago • 2 comments

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 avatar Jan 30 '19 10:01 houli

@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 avatar Jan 30 '19 11:01 Turbo87

@Turbo87 how about adding an assertion called hasAttributeAnyValue() that basically calls hasAttribute with { any: true }?

ghost avatar Oct 09 '20 02:10 ghost