jsdom: `querySelector` cannot resolve selectors with escaped IDs

For example, as a CSS selector, ID as "0foo.000" requires escape the first "0" and "." at least. Current browsers also have CSS.escape(str) builtin for escaping any IDs.

But the current jsdom (9.4.0) cannot resolve the ID above. the code as:

"use strict";

const jsdom = require("jsdom");
const document = jsdom.jsdom();

//(same codes on web console and nodejs)
const elems = document.createElement("div");
const a = document.createElement("span");
a.id = "0foo.000";
elems.appendChild(a);

//fail with jsdom but pass on browsers
console.assert(elems.querySelector("#\\30 foo\\.000") === a);

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Comments: 17 (3 by maintainers)

Commits related to this issue

Most upvoted comments

Doing jest dom manipulation test with jsdom as test environment, found out CSS is not defined. Seems that it is not implemented.