jsdom / jsdom

A JavaScript implementation of various web standards, for use with Node.js
MIT License
20.41k stars 1.7k forks source link

Support the CSS selector :focus-visible in querySelector and matches #3426

Open ranjith-dish opened 2 years ago

ranjith-dish commented 2 years ago

Basic info:

Minimal reproduction case

I face this syntax error exception from react-testing-library.

"@testing-library/react": "12.1.5", "jest": "^29.0.2", "jest-environment-jsdom": "^29.0.2",

document.activeElement.matches(':focus-visible')

=> SyntaxError: ':focus-visible' is not a valid selector

How does similar code behave in browsers?

https://codepen.io/ranjith-dish/pen/MWGaXNo

iamogbz commented 1 year ago

Looks related to https://github.com/jsdom/jsdom/issues/3055

danielmag commented 1 year ago

I'm experiencing the same issue. Is there any workaround?

bschlenk commented 1 day ago

I'm using this as a workaround for now, :focus-visible always returns false:

const matchesOriginal = HTMLElement.prototype.matches
HTMLElement.prototype.matches = function (query: string) {
  if (query === ':focus-visible') return false
  return matchesOriginal.call(this, query)
}