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

react-dnd: Using Proxyquire to stub sub-components in unit tests results in test failure. #76

Closed
cmelion opened this issue Aug 25, 2015 · 6 comments

Comments

@cmelion
Copy link

cmelion commented Aug 25, 2015

Anyone run into this?
react-dnd/react-dnd#268
https://github.com/cmelion/react-hot-boilerplate/tree/Invariant-Violation-DND

@bendrucker
Copy link
Collaborator

Nope. If you can provide more info I can try to look into it. But I don't use React so I won't be able to help much unless you can offer some direction.

@bendrucker
Copy link
Collaborator

Didn't mean to close this. Happy to discuss but we do need more context (and not a link to a lengthy React-specific discussion).

@cmelion
Copy link
Author

cmelion commented Aug 25, 2015

Hey Ben,
Thanks for responding. This certainly isn't an issue with proxyquire and may not be a react-dnd problem either (it might be react contexts in general), I was just hoping someone using proxyquire had run into the problem and had a workaround. Failing that, it seems useful to have some reference here for a solution once it is found, which does not require this issue to remain open.

As far as context, the linked repo demonstrates the issue. Just run npm install, npm test.

A can say with certainty that proxyquire works fine for stubbing out react sub-components and even works for stubbing react-stores with react-DND context wrappers, just not with react DOM components.

@bendrucker
Copy link
Collaborator

Got it. If I can help explain how proxyquire accomplishes what it does, feel free to ask for clarification.

@cmelion
Copy link
Author

cmelion commented Aug 25, 2015

The invariant violation goes away when I omit: "@global': true

Removing @global has the side-effect of breaking

TestUtils.findRenderedDOMComponentWithClass/Tag

which is not a show-stopper.

@cmelion
Copy link
Author

cmelion commented Aug 25, 2015

Issue resolved using:
const subComponent = React.findDOMNode(comp).querySelectorAll('.simple-subcomponent');
should(subComponent.length).equal(1);

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