Material-ui: Portal.js + Fade.js snapshot testing issues

Created on 22 Jul 2018  路  9Comments  路  Source: mui-org/material-ui

Cannot use Dialog in a storybook because ReactDOM.createPortal fails and after I mock ReactDOM.createPortal, Fade.js throws errors

  • [x] This is a v1.x issue.
  • [x] I have searched the issues of this repository and believe that this is not a duplicate.

Expected Behavior

Should be able to snapshot test the Dialog

Current Behavior

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

support

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:

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.

All 9 comments

馃憢 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 instorybook.test.js file, 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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

HZooly picture HZooly  路  63Comments

amcasey picture amcasey  路  70Comments

cfilipov picture cfilipov  路  55Comments

tdkn picture tdkn  路  57Comments

Bessonov picture Bessonov  路  93Comments