Cannot use Dialog in a storybook because ReactDOM.createPortal fails and after I mock ReactDOM.createPortal, Fade.js throws errors
Should be able to snapshot test the Dialog
I have an npm library where I am using @material-ui/core/Dialog. This library has storybooks enabled.
First issue: realized that I have to mock ReactDOM.createPortal:
ReactDom.createPortal = (node) => node;
Second issue: Then struggled for a few hours to understand what is the problem in Fade.js and got stuck at:
Error: TypeError: Cannot set property 'webkitTransition' of undefined
at:
handleExit = node => {
.....
node.style.webkitTransition = theme.transitions.create('opacity', transitionProps);
node.style.transition = theme.transitions.create('opacity', transitionProps);
I just cannot pass over this issue anymore and I don't think I will be the only one having it.
Thanks
馃憢 Thanks for using Material-UI!
We use the issue tracker exclusively for bug reports and feature requests, however,
this issue appears to be a support request or question. Please ask on StackOverflow where the
community will do their best to help. There is a "material-ui" tag that you can use to tag your
question.
If you would like to link from here to your question on SO, it will help others find it.
If your issues is confirmed as a bug, you are welcome to reopen the issue using the issue template.
@liviuignat I doubt we can do much about it. Let's use the issue tracker for issues :).
The same problem. It happened after updating from 4.1.1 to 4.1.2
Same problem here as well moving from 4.1.1 to 4.1.2. Oddly enough, it works just fine for one component, but not for another.
What's the error?
I'm getting this: TypeError: Cannot set property 'webkitTransition' of undefined.
Your tested code probably doesn't forward the ref correctly. We have reverted some changes in #16348. We will release v4.1.3 with the fix. You can revert to v4.1.1 in the meantime.
I'm on v4.7.1 and I was getting this error after migrating from v0 (I know, sorry.). If you're still having trouble with this, this is what fixed it for me:
ReactDOM.createPortal = jest.fn((element, node) => {
if (!element.style) {
return React.cloneElement(element, { style: { webkitTransition: '' } });
}
return element;
});
jest.mock('@material-ui/core/Fade');
Jest tests worked fine, but storybook snapshots would error out. I put this instorybook.test.js file, before initStoryshots. I assume you can put this wherever you setupTests.
I'm on v4.7.1 and I was getting this error after migrating from v0 (I know, sorry.). If you're still having trouble with this, this is what fixed it for me:
ReactDOM.createPortal = jest.fn((element, node) => { if (!element.style) { return React.cloneElement(element, { style: { webkitTransition: '' } }); } return element; }); jest.mock('@material-ui/core/Fade');Jest tests worked fine, but storybook snapshots would error out. I put this in
storybook.test.jsfile, before initStoryshots. I assume you can put this wherever you setupTests.
If anyone's running into this still, it's only necessary to mock transition components (don't need to use createPortal) like so in storybook.test.js. If you do it in your setupTests file, it will affect other tests other than just your snapshots.
Most helpful comment
I'm on v4.7.1 and I was getting this error after migrating from v0 (I know, sorry.). If you're still having trouble with this, this is what fixed it for me:
Jest tests worked fine, but storybook snapshots would error out. I put this in
storybook.test.jsfile, before initStoryshots. I assume you can put this wherever you setupTests.