Skip to content

ReferenceError: Node is not defined #706

@thinkasany

Description

@thinkasany
  • @testing-library/jest-dom version:
  • node version:
  • jest (or vitest) version:
  • npm (or yarn) version:

Relevant code or config:

var your => (code) => here;

What you did:

Upgrading from 6.8.0 to 6.9.0

What happened:

Encountering an error

Run bun run test:node
$ bun run version && jest --config .jest.node.js --no-cache
$ tsx scripts/generate-version.ts
  console.log
    Current React Version: 19.1.1

      at Object.<anonymous> (tests/setup.ts:31:9)

FAIL components/__tests__/node.test.tsx
  ● Test suite failed to run

    ReferenceError: Node is not defined

    > 1 | import '@testing-library/jest-dom';
        | ^
      2 |
      3 | import { toHaveNoViolations } from 'jest-axe';
      4 | import jsdom from 'jsdom';

      at Object.<anonymous> (node_modules/@testing-library/jest-dom/dist/matchers-0a2a9889.js:1986:4)
      at Object.<anonymous> (node_modules/@testing-library/jest-dom/dist/index.js:3:16)
      at Object.require (tests/setupAfterEnv.ts:1:1)

Test Suites: 1 failed, 1 total
Tests:       0 total
Snapshots:   0 total
Time:        1.163 s
Ran all test suites.
error: script "test:node" exited with code 1
Image

Reproduction:

.jest.node.js

const { moduleNameMapper, transformIgnorePatterns } = require('./.jest');

// jest config for server render environment
module.exports = {
  setupFiles: ['./tests/setup.ts'],
  setupFilesAfterEnv: ['./tests/setupAfterEnv.ts'],
  moduleFileExtensions: ['ts', 'tsx', 'js', 'md'],
  moduleNameMapper,
  transform: {
    '\\.tsx?$': './node_modules/@ant-design/tools/lib/jest/codePreprocessor',
    '\\.js$': './node_modules/@ant-design/tools/lib/jest/codePreprocessor',
    '\\.md$': './node_modules/@ant-design/tools/lib/jest/demoPreprocessor',
    '\\.(jpg|png|gif|svg)$': './node_modules/@ant-design/tools/lib/jest/imagePreprocessor',
  },
  testRegex: 'node\\.test\\.(j|t)sx$',
  testEnvironment: 'node',
  transformIgnorePatterns,
  // bail: true,
};

Problem description:

Our repository doesn't lock packages. To promptly identify issues with upstream repositories, we encountered this issue during the 6.9.0 release. However, looking at the release changelog, it's unclear what adjustments were needed.

https://github.com/testing-library/jest-dom/releases/tag/v6.9.0

Suggested solution:

Avoid breaking changes in minor versions

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions