-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Implement SVG support #375
Comments
@EvNaverniouk what version of React are you using? I'm unable to reproduce on the current master branch with any recent major version of React (13, 14, 15). it('should work with svgs', () => {
const wrapper = mount(<svg />);
console.log(wrapper.find('.test'));
}); |
I'm on React 15.0.2, Enzyme 2.3.0, JSDom 9.0.0. I'm also using the |
Can you share the exact code that is failing for you? This should definitely be failing for me as far as I can tell https://jsfiddle.net/1pxpbp0n/, so I'll have to look into it more. edit: it looks like we're using JSDom edit2: Even with JSDom |
@EvNaverniouk are you running this test in a real browser environment at all? Can I see your Using JSDom var svg = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
console.log(svg.className)
// '' Which is incorrect, it should return an object with the shape You can clone https://github.com/Aweary/enzyme-test-repo/tree/issue-%23375 and see that it's passing just fine. Feel free to fork that repo if you can provide a failing test case. |
Using your JSFiddle link, I'm getting an Working on a repo to reproduce the issue now. It seems like it's not as straightforward as I thought. Having trouble reproducing in a clean environment. As soon as I nail it down, I'll post the minimal case. |
@EvNaverniouk right, the reason I asked whether you were testing in a browser environment is because I think jsdom is not handling
Let me know if you're getting an object in jsdom as well, because I'm not and I think that's the issue. |
@EvNaverniouk see jsdom/jsdom#1480 (comment). jsdom does not yet support the SVG DOM so this is not an issue with enzyme just yet. I think that we should likely add support for |
Right. I see what you're saying. Strangely, running my code through JSDom via the terminal is fine -- no errors. But if I run the same test code in Chrome without JSDom, I get the original issue above. Ok. I'll close this and continue by doing a |
@EvNaverniouk yeah that would be expected. Until jsdom supports |
I'm going to reopen this as I think we still want to consider implementing support for this so enzyme can work with SVGs in the browser. |
It seems like the right approach here is to just have a |
yeah sounds about right @lelandrichardson but that something different for SVGs is not testable with our current test setup with jsdom, do we have to test it with karma or something? |
@nfcampos I wouldn't be opposed to having the test suite run with karma as long as we can continue testing the node environment as well (which i believe we could?). This is probably more ideal than testing with jsdom in the first place, though perhaps not as fast. |
Will karma testing work in |
@lelandrichardson yeah I believe we can keep testing both in node (ran with mocha) and in the browser (ran with karma) with the same test code (here's an example of a repo that runs both mocha and karma https://github.com/jxnblk/reflexbox/blob/master/package.json) but I think whatever we do with karma we should continue testing with mocha + jsdom because that's how most people use it I think |
@ljharb it does. you can use chrome headless or phantomjs. I've used both before. Oddly enough, the one thing I haven't done is use karma to run node tests... i wonder if there is a |
I'm 👍 on running the test suite in a browser environment. If our users are doing it, we should be too. |
Sorry, I'd just like to add one more thing in case it helps track down things. This original issue came out as a result of upgrading from enzyme 2.2.0 to 2.3.0. Downgrading back to 2.2.0 makes my errors go away. |
@EvNaverniouk interesting. that's helpful... we should set up a test case and run git bisect on it. |
@lelandrichardson this error was introduced by my first PR that fixed whitespace issues (it introduced the |
oh interesting. so previously it was calling |
Yeah exactly, so it's not really a regression as much as it is a change that is throwing an error in a situation where we'd really want it to throw since it's not supported just yet. |
find()
breaks when <svg/>
elements are mounted
I'm getting the same error on Chrome trying to access a dom element with a svg. |
This might be simplifying it a little bit? But it did the trick for me.. |
Ran into this with |
Has there been any progress on this? All of our tests that try to mount an svg are currently disabled for this reason. |
Thanks for checking! I'm going to close this out then, as it seems it's been resolved 👍 |
I read the solution to use classList instead, but I'm getting confuse can someone please tell me what will be the solution of @EvHaus example using classList?
|
When using
.find()
on components with an<svg/>
tag, enzyme explodes with:Here is a very short and simple test case to reproduce the issue:
The problem is that SVG elements do not report their className as a string, but as an object instead.
The text was updated successfully, but these errors were encountered: