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

global is not defined #985

Closed
JesusTheHun opened this issue Jun 21, 2021 · 6 comments
Closed

global is not defined #985

JesusTheHun opened this issue Jun 21, 2021 · 6 comments

Comments

@JesusTheHun
Copy link

  • @testing-library/dom version: 7.31.2
  • Testing Framework and version: jest@27.0.4, @testing-library/react@11.2.7
  • DOM Environment: @testing-library/jest-dom@5.14.1

Running Chrome

What you did:

I tried to use rtl in a vitejs project. This builder uses esbuild, which is a lot more closed to the ECMAScript spec and therefore is more strict.

What happened:

Uncaught ReferenceError: global is not defined at node_modules/@testing-library/dom/node_modules/pretty-format/build/plugins/AsymmetricMatcher.js (AsymmetricMatcher.js:10)

Referencing this line of code : var Symbol = global['jest-symbol-do-not-touch'] || global.Symbol;

Problem description:

While rtl is supposed to be used by nodejs, the package is by default compiled by esbuild and send to the browser, leading to this error.

Suggested solution:

Despite being unrelated to RTL directly, it would be very convenient if you could simply add a check to make sure global exists before going further.

@eps1lon
Copy link
Member

eps1lon commented Jun 21, 2021

This should be fixed in our alpha. Could you try it with @testing-library/react@alpha and report back if the issue persists? For me information about breaking changes in the alpha check out #979

@JesusTheHun
Copy link
Author

Using the alpha, the problems appears somewhere else :

Uncaught ReferenceError: global is not defined at node_modules/pretty-format/build/plugins/AsymmetricMatcher.js (AsymmetricMatcher.js:10) at __require2 (chunk-IHTDASF6.js?v=60a1262a:17) at node_modules/pretty-format/build/index.js (index.js:14) at __require2 (chunk-IHTDASF6.js?v=60a1262a:17) at dom.esm.js:3

dom.esm.js from node_modules/@testing-library/react/node_modules/@testing-library/dom/dist/@testing-library/dom.esm.js

@eps1lon
Copy link
Member

eps1lon commented Jun 21, 2021

@JesusTheHun Could you provide a repro? Preferably a cloneable repository.

@JesusTheHun
Copy link
Author

I've created a simple vitejs project with a storybook and some tests, but the error doesn't show up. I will try to get a repro but it will probably take a bit of time.

@JesusTheHun
Copy link
Author

I spent a lot of time on this and I still can't make it go into error.

@eps1lon
Copy link
Member

eps1lon commented Jun 22, 2021

Sounds like an issue with your test setup. Feel free to re-open once you can reproduce the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants