-
Notifications
You must be signed in to change notification settings - Fork 128
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 variable is not available in the module #181
Comments
What do you mean with 'both of these variables are available before rewiring'? Looking at the source code of Even if in the file you are currently working in, you have declared |
Hi @rensbaardman, thanks for the answer.
I didn't declare them locally. They are already available in the global declarations. The example which I gave here is the full listing of the file. |
I see. The problem probably lies with the different scope of By the way, I have to say that modifying the |
Hi @rensbaardman, sorry, I had to provide a little bit more context: My file (which I test) depends on 3rd party materializecss library. This library is quite old-school and doesn't export much. In most cases it relies on global nature of declarations inside a browser. I.e. it just sets And my file depends on a
I had a setup.js file for Jest (it's just any file, which runs before any tests) which looked like this:
I could assume, that this import could be available only inside setup.js
The problem, that I'm not using this class directly. It's used in another .js from that library (e.g. select.js:13) |
Alright, but where/how are |
Maybe I'm confusing something here, I'm not that good with JS. Here is my reasoning, may be I understand JS variable scoping wrong: I don't know how Jest (or jsdom) injects the Also, Jest has no clue about
Also, if I remember correctly, I tried to debug this rewiring. Before entering PS thanks for your time and trying to understand the issue! |
Hmmm... that's interesting. I wouldn't know why calling |
Hi @rensbaardman could you check this one, please? There is an entry point: case_181.test.js, where I import a file, which sets global variable
Only rewired class fails to print it
Output:
|
Hi, I'm trying to add a non-exported 3rd party class to global scope, using rewire
The class looks like this: https://github.com/Dogfalo/materialize/blob/v1-dev/js/component.js
I'm doing it this way:
And it almost works, but inside component.js, there are usages of
Element
andcash
. And during runtime, they fail as "is not defined"I managed to solve the problem by:
And it works.
However, it seems very strange to me, since both of these variables are available before rewiring. Is there any way to add these globals implicitly?
I think it might be the same problem: #99
The text was updated successfully, but these errors were encountered: