nathanboktae / chai-dom

DOM assertions for the Chai assertion library using vanilla JavaScript
Other
76 stars 26 forks source link

Fix `displayed` to work with elements in the Shadow DOM #64

Closed jpzwarte closed 1 year ago

jpzwarte commented 1 year ago

Fixes #63

jpzwarte commented 1 year ago

@nathanboktae Could you review this please?

eKoopmans commented 1 year ago

This LGTM! The same broken check is present in visible as well: https://github.com/nathanboktae/chai-dom/blob/master/chai-dom.js#L365

Would be great to get a fix merged for both of these! The only potential issue is browser support, not sure if it's a concern (e.g. no IE support): https://caniuse.com/mdn-api_node_getrootnode

nathanboktae commented 1 year ago

Thanks. This does cut off support for IE11, but that time has long come.

eKoopmans commented 1 year ago

Cool, thanks for merging! Do you want me to put up a PR for visible?

If you did want to maintain backwards compatibility btw, this is an option:

    var el = flag(this, 'object'),
        isAttached = el.getRootNode ? el.getRootNode({ composed: true }) === document : document.body.contains(el),
        actual = isAttached ? window.getComputedStyle(el).display : el.style.display