question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

The color-contrast check doesn't work in JSDOM

See original GitHub issue

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.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:10 (6 by maintainers)

github_iconTop GitHub Comments

4reactions
paschalidicommented, Nov 25, 2021

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

1reaction
strakercommented, 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
Read more comments on GitHub >

github_iconTop Results From Across the Web

axe-core - npm
Currently the color-contrast rule is known not to work with JSDOM. We can only support environments where features are either natively supported or...
Read more >
Building your own color contrast checker - DEV Community ‍ ‍
There are many great online tools that can help you check the color contrast, but in this post I am going to show...
Read more >
Contrast Checker - WebAIM
Enter a foreground and background color in RGB hexadecimal format (e.g., #FD3 or #F7DA39) or choose a color using the color picker. The...
Read more >
Does Siteimprove check color contrast in Accessibility?
Yes, Siteimprove checks for color contrast issues in Accessibility using guidelines described below. The color contrast ratio required ...
Read more >
Text elements must have sufficient color contrast against the ...
Use the color contrast analyzer below to find colors that pass the guidelines. Color Contrast Analyzer. Foreground Color. Hex: RGB:
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found