Closed iamrandys closed 9 years ago
Could you post a little more code, maybe one of your React component modules?
I'll create a simplified project that exposes the issue. I'll probably figure it out once I do this.
On Sep 1, 2014, at 5:20 AM, Matt Hinchliffe notifications@github.com wrote:
Could you post a little more code, maybe one of your React components?
— Reply to this email directly or view it on GitHub.
That would be great if you could, nobody wants an unsolved mystery!
Ok, I've figured it out. After I upgraded to karma-bro 0.7.0, the issue was consistent so I was able to track it down. If you have a react component with mixins defined, the get and set are defined both on the component and the mixin. When React extends the component with the mixin, there are two get methods and it throws an invariant violation. So the issue isn't with any package, it's just a side effect of the way React behaves in a test environment when using mixins. Now I just have to come up with a way to disable mixins when doing unit tests.
I was able to move the mixins to another module and then clear the array before requiring the component that used the mixins so that there would not be any mixins included during unit tests.
mixinsModule.get('mixins').length = 0;
Thanks @iamrandys, I appreciate the extra time and effort finding out the issue. It did sound like a symptom of something hiding within the complexity of the setup. Hopefully this will be a useful reference for somebody.
But how is this a fix? Wouldn't clearing the mixins break the component?
The problem does not seem to be solved, rewireify is unusable in its current state as it tried to apply getters and setters mutliple times to mixins. The solution mentioned above does not work as the error occurs when processing require constructs during initialisation.
Could you supply some example code?
Always happy to accept a PR too.
I'll see what i can do, is there a way of stubbing out deeply nested components
It wouldn't be too hard to add a filter, in terms of actually understanding the dependency tree I don't know.
Since my last post we have been ignoring mixins using the rewireify --ignore option in karma. It would be nice to be able to supply a "*-mixin" wildcard to the ignore option though.
I don't see that this is an issue with rewireify. It does what it is suppose to do. It just doesn't play well when testing React components that use mixins.
Ok. Is it possible to set rewire a child component inside a component.
A has child B which has a private var i want to override. On 1 Apr 2015 02:20, "iamrandys" notifications@github.com wrote:
Since my last post we have been ignoring mixins using the rewireify --ignore option in karma. It would be nice to be able to supply a "*-mixin" wildcard to the ignore option though.
I don't see that this is an issue with rewireify. It does what it is suppose to do. It just doesn't play well when testing React components that use mixins.
— Reply to this email directly or view it on GitHub https://github.com/i-like-robots/rewireify/issues/3#issuecomment-88302781 .
I've had a think about this, it would be nice if the --ignore
option could take an array of glob patterns instead of specific paths.
I agree this would be really nice. I could include *mixin and I would have to keep updating this setting.
On Apr 16, 2015, at 5:17 AM, Matt Hinchliffe notifications@github.com wrote:
I've had a think about this, it would be nice if the --ignore option could take an array of glob patterns instead of specific paths.
— Reply to this email directly or view it on GitHub.
@iamrandys If you'd like you can now pull down https://github.com/i-like-robots/rewireify/pull/9 and see if it meets your needs.
Oh sweet! I'll definitely will test it out and let you know how it works out. Thanks for the help!
On May 14, 2015, at 5:58 AM, Matt Hinchliffe notifications@github.com wrote:
@iamrandys If you'd like you can now pull down #9 and see if it meets your needs.
— Reply to this email directly or view it on GitHub.
Modules can now be ignored via pattern in 69a131a9a9aab1eec4bfc540e7b9da8d4b2dd4c6
Error: Invariant Violation: ReactCompositeComponentInterface: You are attempting to define
__get__
on your component more than once. This conflict may be due to a mixin.First off, I do not believe this is a rewireify issue (rewirify has been solid), but from the error message this seems the most logical place for others to look for this issue.
About 1 out of 10 times and only on initial Karma startup, I get the following error and Karma hangs. It is very hard to troubleshoot the issue since it does not happen all the time. I am using: