dom-testing-library: Regression: "ReferenceError: global is not defined"

  • @testing-library/dom version: 7.22.6
  • Testing Framework and version: QUnit 2.11.0
  • DOM Environment: Chrome 84.0.4147.135 (via Testem)

Relevant code or config:

import { screen } from "@testing-library/dom";

What you did:

I ran my tests: ember test --server.

What happened:

Tests couldn’t be executed, the following error was thrown:

ReferenceError: global is not defined
    at Object../node_modules/pretty-format/build/plugins/AsymmetricMatcher.js (test-support.js:37305)
    at __webpack_require__ (test-support.js:18993)
    at Object../node_modules/pretty-format/build/index.js (test-support.js:36889)
    at __webpack_require__ (test-support.js:18993)
    at Module../node_modules/@testing-library/dom/dist/@testing-library/dom.esm.js (test-support.js:19861)
    at __webpack_require__ (test-support.js:18993)
    at Module.callback (test-support.js:19106)
    at Module.exports (vendor.js:118)
    at Module._reify (vendor.js:155)
    at Module.reify (vendor.js:142)

Reproduction:

Problem description:

@testing-library/dom 7.22.3 was working fine.

@testing-library/dom 7.22.6 doesn’t work.

Suggested solution:

I can see there was a bump of pretty-format between 7.22.3 and 7.22.6: https://github.com/testing-library/dom-testing-library/commit/9cbc4280d4eceddc5511c21114455f73cd31d196, perhaps it’s the culprit.

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 1
  • Comments: 22 (7 by maintainers)

Commits related to this issue

Most upvoted comments

Adding this dev dep solves the error for me (jest 27) "jest-environment-jsdom": "~27.0"

this is a problem only when running tests with jest 27

Thanks. I see the issue and think I know how to solve it. I just want to get the fix right so that we don’t regress in the future.

pretty-format caused us quite some trouble in the past since it’s part of the jest stack which doesn’t work in a browser. So using any package from that stack in a browser is always sketchy because it’s untested. But we do want to use it so that the formatting in our library is familiar.

Sorry to comment on closed issue, but I still have the same problem. I’m using wtr and vite. (So, fully esm and browser environment).

This is wtr config. nothing special:

import vite from 'vite-web-test-runner-plugin';
export default {
    nodeResolve: true,
    esbuildTarget: 'auto',
    files: 'src/**/__tests__/**/*.test.js',
    plugins: [
        vite()
    ]
};

This is the stack trace:

ReferenceError: global is not defined
        at ../node_modules/.pnpm/pretty-format@26.6.2/node_modules/pretty-format/build/plugins/AsymmetricMatcher.js (node_modules/.vite/@testing-library_vue.js:11652:19)
        at __require2 (node_modules/.vite/chunk-IHTDASF6.js:17:44)
        at ../node_modules/.pnpm/pretty-format@26.6.2/node_modules/pretty-format/build/index.js (node_modules/.vite/@testing-library_vue.js:12372:53)
        at __require2 (node_modules/.vite/chunk-IHTDASF6.js:17:44)
        at ../node_modules/.pnpm/@testing-library+dom@7.31.2/node_modules/@testing-library/dom/dist/@testing-library/dom.esm.js (node_modules/.vite/@testing-library_vue.js:25879:39)
        at __init (node_modules/.vite/chunk-IHTDASF6.js:14:50)
        at ../node_modules/.pnpm/@testing-library+vue@6.5.0_df3f769d1ea316852686577c1510cc0d/node_modules/@testing-library/vue/dist/render.js (node_modules/.vite/@testing-library_vue.js:27069:17)
        at __require2 (node_modules/.vite/chunk-IHTDASF6.js:17:44)
        at ../node_modules/.pnpm/@testing-library+vue@6.5.0_df3f769d1ea316852686577c1510cc0d/node_modules/@testing-library/vue/dist/index.js (node_modules/.vite/@testing-library_vue.js:27329:19)
        at __require2 (node_modules/.vite/chunk-IHTDASF6.js:17:44)

@Bulletninja This is still the latest status:

I personally don’t have the bandwidth to fix this.