Skip to content

"'button#test-btn.sm,,,Ahidden' is not a valid selector" if first class entry contains colon #153

Description

@jklingen

The error is occurring in an environment that uses Jest, testing-library, tailwind.css and others - and only if the element to be selected (in this case, via screen.getByRole()) has a colon in the first class entry (e.g. class="sm:hidden foo"). After flipping the classes, the error does not occur.

Affected versions: 2.2.21 and 2.2.22 (had no issues with 2.2.20)

After inspecting at a breakpoint, the issue seems to be that class entry is URL-encoded to sm%3Ahidden in nwsapi, which then ends up as sm,,,Ahidden in the selector.

The issue is probably related to what two other users describe here:

Since I am not using nwsapi directly, I wasn't able to create a minimal reproduction with reasonable effort. So I asked AI, and here's what they came up with. I don't know for sure whether that's how nwsapi is to be used; anyway, I hope it helps for a better understanding of what's happening.

const { JSDOM } = require('jsdom');
const nwsapi = require('nwsapi');
const domInstance = new JSDOM('<!DOCTYPE html><body><button class="sm:hidden" id="test-btn">Test</button></body>');
const { window } = domInstance;
const { document } = window;

const dom = nwsapi(window);
const btn = document.getElementById('test-btn');
dom.select(':scope', btn);


Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions