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
Unable to require() to use with Jest #2129
Comments
I'm also getting this error, not sure if it's a problem with c3 or jsdom. Create an empty npm project. Then, try this:
Output:
I wasn't getting this error before. |
Do you think we can just mock the SVGPathElement property? I think it's obviously a problem with jsdom's incomplete SVG implementation (which I don't blame them for; that shit sounds like it sucks) However, what would be a good workaround? I want to be able to unit test a project that has C3 as a dependency with jsdom/jest, but this is a pretty big blocker. I don't actually need to unit test any of the C3 functionality so I guess I could stub it out... |
That would be a possible solution. I'm not even using c3, but probably other packages of my project are. |
Found it! Rolling keen-js back to v3.4.1 "solved" the problem. Latest version is 4.0.0. In case of anyone with the same issue as mine, Keen decided to divide their main package into 3 separated packages: https://github.com/keen/keen-js/releases/tag/v4.0.0 The problem is that keen-dataviz.js uses c3.js. I'm not using charts, so for my case the solution is to install keen-tracking and remove keen-js. |
I'm facing the same problem using jest, and trying to snapshot a component that uses react-c3js
just some differences on line number, probably some build related (I'm using c3 version : 0.4.18) update: ps: works perfectly on browser, just on jest happens this error |
Same here. I believe this one answers why: jsdom/jsdom#1423 |
@brandonros I was able to require c3.js in node environment by dummying window.SVGPathElement like the below:
|
@fernandes I'm facing a similar problem. Have you been able to find a workaround? |
hi @esonmez , I hadn't... as I've researched jsdom doesn't implement the SVG stuff on it, that's why can't use c3 on tests (that uses jdsom), I just isolated the c3 component as much as I could and dropped this test heheh |
@fernandes Got it. I played around with it a bit more and was able to run the snapshot tests by mocking c3: // __mocks__/c3.js
module.exports = () => 'c3'; and then in the Jest config portion of my "moduleNameMapper": {
"c3": "<rootDir>/__mocks__/c3.js",
} |
hahaha that's interesting, thanks for sharing the tip, I'm gonna implement on my project, thank you! |
I was excited to solve this using @esonmez's suggestion, but since the project I'm working on leverages create-react-app, I got stuck again:
Frustrating to say the least. In any case, in our jest setup file, I was able to mock it just like @kt3k did:
And that worked like a charm. Thanks for the help all! |
For questions involving the interplay between C3.js and any other library (react, vuejs, ..) please use the Google Group at https://groups.google.com/forum/#!forum/c3js. Thank you! |
which is
I'm not quite sure where to report this. Jest, jsdom, here?
The text was updated successfully, but these errors were encountered: