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
setState causes Invariant Violation when it changes markup #58
Comments
Hmm. Surprised this is happening. I will look into it as soon as I get a sec. |
@silvenon I'm looking into this but it looks like React 0.14 has a hard dependency on In the mean time, you should be able to get this working by requiring
note that the usage of I'm working on a less brittle way to fix this... |
I managed to keep my precious // test/global.js
import jsdom from 'jsdom';
global.document = jsdom.jsdom('');
global.window = document.defaultView;
global.navigator = window.navigator; And passing I also had to define Thanks, it works now 😃 |
I realized that my solution only initializes the document once, is this bad? |
@silvenon it depends. Doing so can simplify a lot of things. some libraries will cache a reference to the document at require time (like jquery) and thus you have to jump through a lot of hoops to have code work when using a new document for every test. We plan on using only a single document for our entire test suite at airbnb soon, but we don't yet. As far as react goes, enzyme's Also, you should be able to refresh the document later on in your tests and react will work just fine with it. React doesn't cache any document references AFAICT, it just uses whatever document is off the global. |
Thanks for the detailed explanation 👍 Learning so much from you guys. |
Closing this issue as it should now be "fixed". This problem should no longer exist so long as you have a global |
…rouslyReplaceNodeWithMarkup See enzymejs/enzyme#58
…rouslyReplaceNodeWithMarkup See enzymejs/enzyme#58 Signed-off-by: Erik Wyatt <kire321@gmail.com> Signed-off-by: Ádám Gólya <adam.stork@gmail.com>
…rouslyReplaceNodeWithMarkup See enzymejs/enzyme#58 Signed-off-by: Erik Wyatt <kire321@gmail.com> Signed-off-by: Ádám Gólya <adam.stork@gmail.com>
…rouslyReplaceNodeWithMarkup See enzymejs/enzyme#58 Signed-off-by: Erik Wyatt <kire321@gmail.com> Signed-off-by: Ádám Gólya <adam.stork@gmail.com>
Polluting the global document causes side effects among tests, they basically share the DOM thus causing nasty behaviors when running multiple tests with Mocha for example. So that workaround fixes one problem but causes others |
Hey all - just for reference, requiring |
I'm aware of #27, mine happens on React v0.14 and it crushes my soul as well 😞
As far as I've tested (AFAIT?), this only happens when the state alters markup:
This does not happen if both elements are the same (e.g.
this.state.flag ? <div /> : <div />
).Jest seemed to have solved this issue, it doesn't happen there, so it might be worth looking how they did it. I can take a look later, but I was wondering if you knew what's causing this.
This SO answer might help, though I'm not sure if it's related.
The text was updated successfully, but these errors were encountered: