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

Add `HTMLLinkElement` as eligible `.disabled` element

Open gossi opened this issue 2 years ago • 4 comments

When trying to write tests for a HTMLLinkElement and check for .disabled state, instead of asserting, qunit-dom throw an error.

There is a little gotcha for disabled on <link>.

  • As per declarative API (<link disabled>), this is experimental, deprecated and advised against its usage (and also does not work in browsers)
  • As per imperative API (HTMLLinkElement.disabled), this is according to MDN allow and works in browsers

So, this PR adds HTMLLinkElement as eligible element to check this for 😃

gossi avatar Dec 20 '22 02:12 gossi

but... why? 😂

is there a legitimate use case for something like this? 😅

Turbo87 avatar Dec 20 '22 07:12 Turbo87

In fact yes, there is 😅

When each <link> represents a theme and only one can be active, then make the others .disabled in which case the browser don't use that CSS. That's the state when CSS is loaded but not in use (which is for what I'm writing the test for).

gossi avatar Dec 20 '22 11:12 gossi

and why not remove the link elements instead? 🤔

Turbo87 avatar Dec 20 '22 12:12 Turbo87

that's implementation details of my particular library.

The point is, the provided API (isDisabled() and isNotDisabled()) is here to check for a disabled property on any * extends HTMLElement that supports it. However, this is subjectively constrained by qunit-dom and doesn't match reality. I figured HTMLLinkElement is missing from that list and I wouldn't be surprised if there are more.

I see this more of a bugfix, so the API keeps holding up to its promise :)

gossi avatar Dec 20 '22 14:12 gossi