Skip to content

[Bug]: Syntaxt error on .closest(selector:has(+ selector)) #15321

Open

Description

Version

28.1.3

Steps to reproduce

const ancestor = myElement.closest('.thisClass:has(+ .thisClass)')

Expected behavior

No syntax error found.

Actual behavior

Jest is flagging a syntax error:
SyntaxError: '+.thisClass,.thisClass' is not a valid selector

Additional context

I'm basically finding a parent of myElement that has a class of .thisClass that has a sibling with the same class.
It perfectly works on execution of the script, I can see no JS documentation saying it is not a valid selector, but Jest says it is...

I tried to replace .closest() by .querySelector() and it is accepted.
I tried to remove the + sign, and it is accepted.

Environment

System:
  OS: MacOS 14.7
  CPU: M3 pro
Binaries:
  Node: 20.9.0
  npm: 10.1.0
npmPackages:
  jest: 28.1.3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions