Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The color-contrast check doesn't work in JSDOM #595

Closed
thecristen opened this issue Nov 1, 2017 · 11 comments
Closed

The color-contrast check doesn't work in JSDOM #595

thecristen opened this issue Nov 1, 2017 · 11 comments

Comments

@thecristen
Copy link

Hi there, thanks for building this fantastic library!

I've never gotten bad color contrast to create violations when testing React components with JSDOM. It seems to always return a false passing result (well, when it's not timing out, but that's a known JSDOM issue). I've created an example based off of this project's jest+react example here.

I'm guessing it doesn't work because JSDOM has not implemented ranges as part of its DOM implementation, and the code that checks for color contrast depends on that (document.createRange()). But the false passing result is a bit concerning.

@dylanb
Copy link
Contributor

dylanb commented Nov 1, 2017

@thecristen what do you mean by "false passing result"? Is it returning this in the violations array or in the incomplete array?

@marcysutton
Copy link
Contributor

I would just turn off the color contrast rule in JSDOM, because you're right that it won't ever work. We don't recommend testing color contrast in JSDOM due to the lack of support.

@dylanb
Copy link
Contributor

dylanb commented Nov 1, 2017

@marcysutton yes, but it should be passing the results for this rule back in the incomplete array - no?

@thecristen
Copy link
Author

Thanks for the comments, this made me look at it a bit carefully. I shouldn't have taken the absence of violations as a "passing" indication (though, I've seen too many tests follow that pattern..). @dylanb you're right in that the results end up in the incomplete array - that's great!

@kalpeshsingh
Copy link

Thanks for the comments, this made me look at it a bit carefully. I shouldn't have taken the absence of violations as a "passing" indication (though, I've seen too many tests follow that pattern..). @dylanb you're right in that the results end up in the incomplete array - that's great!

Curious to know what was your next step here? Did you remove this from unit testing as it requires manual intervention?

@mohanraj-r
Copy link
Contributor

@dylanb @marcysutton looks like the range and selection APIs were added to JSDOM in v16 (jsdom/jsdom#2719). Does this mean color contrast checks can work with axe-core in JSDOM? Does it need any updates to axe-core or should it work as is with JSDOM v16 or higher?

@straker
Copy link
Contributor

straker commented Nov 9, 2021

@mohanraj-r I tested out jsdom 18.0.1. Looks like something about the range API is still not fully working as I get this error when running a test:

"message": "`TypeError: range.getClientRects is not a function` - feature unsupported in your environment. Skipping color-contrast rule.",
        "ruleId": "color-contrast",
        "stack": "Error\n    at new SupportError (axe-core/doc/examples/jsdom/node_modules/axe-core/axe.js:52:18)\n    at Rule.run2 [as run] (axe-core/doc/examples/jsdom/node_modules/axe-core/axe.js:19961:16)\n    at axe-core/doc/examples/jsdom/node_modules/axe-core/axe.js:20719:15\n    at pop (axe-core/doc/examples/jsdom/node_modules/axe-core/axe.js:6649:18)\n    at Object.defer (axe-core/doc/examples/jsdom/node_modules/axe-core/axe.js:6671:11)\n

@paschalidi
Copy link

Seeing the same here. Is there any known fix for this?

@straker
Copy link
Contributor

straker commented Jan 3, 2022

Unfortunately without full support of the APIs we use, there's not much we can do for a fix. I just tested with jsom 19 and still am getting the not supported message.

`TypeError: range.getClientRects is not a function` - feature unsupported in your environment. Skipping color-contrast rule

@tounsoo
Copy link

tounsoo commented Nov 22, 2022

Is this still the case? Or does anyone know another alternative library that will check for color contrast?

@ashleyfigure
Copy link

@tounsoo I'm a little late to the party but we've been using axe-core with Cypress to test color contrast. Cypress runs tests in a browser vs JSDOM.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants