Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: ReferenceError: CSS is not defined #14915

Closed
joonass-visma opened this issue Feb 22, 2024 · 2 comments
Closed

[Bug]: ReferenceError: CSS is not defined #14915

joonass-visma opened this issue Feb 22, 2024 · 2 comments

Comments

@joonass-visma
Copy link

Version

29.7.0

Steps to reproduce

  1. Init new npm project.
  2. Install jest and jest-environment-jsdom
  3. Create file jest.config.json with {"testEnvironment": "jsdom"}
  4. Create file css.test.js with following content:
test('CSS', () => {
  expect(CSS.escape('.foo#bar')).toBe('\\.foo\\#bar');
});

Expected behavior

Should handle CSS interface method calls without crashing.

Actual behavior

Crashes with "ReferenceError: CSS is not defined"

Additional context

Apparently this is caused by jest-environment-jsdom using outdated version of jsdom which did not have support for CSS interface at the time. So either jsdom should be updated or at least provide official workarounds in the documentation for situations where jest-environment-jsdom does not handle a specific web API.

Environment

OS: Windows 11
npm v10.2.3
node v18.19.0
@SimenB
Copy link
Member

SimenB commented Feb 22, 2024

Newer JSDOM versions have dropped support for the Node versions we support, so you'll need to bring your own. https://www.npmjs.com/package/@jest/environment-jsdom-abstract can help reduce the boilerplate (I should've added a readme, but you can essentially copy https://github.com/jestjs/jest/tree/v30.0.0-alpha.3/packages/jest-environment-jsdom and replace the version of jsdom)

@SimenB SimenB closed this as not planned Won't fix, can't repro, duplicate, stale Feb 22, 2024
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 24, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants