Skip to content
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

[test] react-test-renderer coverage #16523

Merged
merged 4 commits into from
Jul 15, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion packages/material-ui/src/Backdrop/Backdrop.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@ describe('<Backdrop />', () => {
inheritComponent: 'div',
mount,
refInstanceof: window.HTMLDivElement,
skip: ['componentProp'],
skip: [
'componentProp',
// react-transition-group issue
'reactTestRenderer',
],
}));

it('should render a backdrop div', () => {
Expand Down
6 changes: 5 additions & 1 deletion packages/material-ui/src/Dialog/Dialog.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,11 @@ describe('<Dialog />', () => {
inheritComponent: Modal,
mount,
refInstanceof: window.HTMLDivElement,
skip: ['componentProp'],
skip: [
'componentProp',
// react-transition-group issue
'reactTestRenderer',
],
}),
);

Expand Down
6 changes: 5 additions & 1 deletion packages/material-ui/src/Drawer/Drawer.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,11 @@ describe('<Drawer />', () => {
inheritComponent: 'div',
mount,
refInstanceof: window.HTMLDivElement,
skip: ['componentProp'],
skip: [
'componentProp',
// react-transition-group issue
'reactTestRenderer',
],
}),
);

Expand Down
6 changes: 5 additions & 1 deletion packages/material-ui/src/Fade/Fade.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@ describe('<Fade />', () => {
inheritComponent: Transition,
mount,
refInstanceof: window.HTMLDivElement,
skip: ['componentProp'],
skip: [
'componentProp',
// react-transition-group issue
'reactTestRenderer',
],
}));

describe('transition lifecycle', () => {
Expand Down
6 changes: 5 additions & 1 deletion packages/material-ui/src/Grow/Grow.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,11 @@ describe('<Grow />', () => {
inheritComponent: Transition,
mount,
refInstanceof: window.HTMLDivElement,
skip: ['componentProp'],
skip: [
'componentProp',
// react-transition-group issue
'reactTestRenderer',
],
}),
);

Expand Down
6 changes: 5 additions & 1 deletion packages/material-ui/src/Menu/Menu.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,11 @@ describe('<Menu />', () => {
inheritComponent: Popover,
mount,
refInstanceof: window.HTMLDivElement,
skip: ['componentProp'],
skip: [
'componentProp',
// react-transition-group issue
'reactTestRenderer',
],
}));

describe('event callbacks', () => {
Expand Down
7 changes: 6 additions & 1 deletion packages/material-ui/src/Modal/Modal.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,12 @@ describe('<Modal />', () => {
inheritComponent: 'div',
mount,
refInstanceof: window.HTMLDivElement,
skip: ['rootClass', 'componentProp'],
skip: [
'rootClass',
'componentProp',
// https://github.com/facebook/react/issues/11565
'reactTestRenderer',
],
}),
);

Expand Down
6 changes: 5 additions & 1 deletion packages/material-ui/src/Popover/Popover.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,11 @@ describe('<Popover />', () => {
inheritComponent: Modal,
mount,
refInstanceof: window.HTMLDivElement,
skip: ['componentProp'],
skip: [
'componentProp',
// react-transition-group issue
'reactTestRenderer',
],
}));

describe('root node', () => {
Expand Down
6 changes: 5 additions & 1 deletion packages/material-ui/src/Popper/Popper.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,11 @@ describe('<Popper />', () => {
inheritComponent: 'div',
mount,
refInstanceof: window.HTMLDivElement,
skip: ['componentProp'],
skip: [
'componentProp',
// https://github.com/facebook/react/issues/11565
'reactTestRenderer',
],
}));

describe('prop: placement', () => {
Expand Down
6 changes: 5 additions & 1 deletion packages/material-ui/src/Slide/Slide.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,11 @@ describe('<Slide />', () => {
inheritComponent: Transition,
mount,
refInstanceof: window.HTMLDivElement,
skip: ['componentProp'],
skip: [
'componentProp',
// react-transition-group issue
'reactTestRenderer',
],
}),
);

Expand Down
6 changes: 5 additions & 1 deletion packages/material-ui/src/Snackbar/Snackbar.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@ describe('<Snackbar />', () => {
inheritComponent: 'div',
mount,
refInstanceof: window.HTMLDivElement,
skip: ['componentProp'],
skip: [
'componentProp',
// react-transition-group issue
'reactTestRenderer',
],
}));

describe('prop: onClose', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,11 @@ describe('<SwipeableDrawer />', () => {
inheritComponent: Drawer,
mount,
refInstanceof: window.HTMLDivElement,
skip: ['componentProp'],
skip: [
'componentProp',
// https://github.com/facebook/react/issues/11565
'reactTestRenderer',
],
}));

it('should render a Drawer and a SwipeArea', () => {
Expand Down
41 changes: 21 additions & 20 deletions packages/material-ui/src/Tabs/Tabs.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export const styles = theme => ({
overflow: 'hidden',
minHeight: 48,
WebkitOverflowScrolling: 'touch', // Add iOS momentum scrolling.
display: 'flex',
},
/* Styles applied to the flex container element. */
flexContainer: {
Expand Down Expand Up @@ -102,6 +103,7 @@ const Tabs = React.forwardRef(function Tabs(props, ref) {
});
const valueToIndex = new Map();
const tabsRef = React.useRef(null);
const childrenWrapperRef = React.useRef(null);

const getTabsMeta = () => {
const tabsNode = tabsRef.current;
Expand All @@ -121,7 +123,7 @@ const Tabs = React.forwardRef(function Tabs(props, ref) {

let tabMeta;
if (tabsNode && value !== false) {
const children = tabsNode.children[0].children;
const children = childrenWrapperRef.current.children;

if (children.length > 0) {
const tab = children[valueToIndex.get(value)];
Expand Down Expand Up @@ -360,30 +362,29 @@ const Tabs = React.forwardRef(function Tabs(props, ref) {

return (
<Component className={clsx(classes.root, className)} ref={ref} {...other}>
<div className={classes.flexContainer}>
{conditionalElements.scrollButtonLeft}
{conditionalElements.scrollbarSizeListener}
{conditionalElements.scrollButtonLeft}
{conditionalElements.scrollbarSizeListener}
<div
className={clsx(classes.scroller, {
[classes.fixed]: !scrollable,
[classes.scrollable]: scrollable,
})}
style={scrollerStyle}
ref={tabsRef}
role="tablist"
onScroll={handleTabsScroll}
>
<div
className={clsx(classes.scroller, {
[classes.fixed]: !scrollable,
[classes.scrollable]: scrollable,
className={clsx(classes.flexContainer, {
[classes.centered]: centered && !scrollable,
})}
style={scrollerStyle}
ref={tabsRef}
role="tablist"
onScroll={handleTabsScroll}
ref={childrenWrapperRef}
>
<div
className={clsx(classes.flexContainer, {
[classes.centered]: centered && !scrollable,
})}
>
{children}
</div>
{mounted && indicator}
{children}
</div>
{conditionalElements.scrollButtonRight}
{mounted && indicator}
</div>
{conditionalElements.scrollButtonRight}
</Component>
);
});
Expand Down
6 changes: 5 additions & 1 deletion packages/material-ui/src/Zoom/Zoom.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@ describe('<Zoom />', () => {
inheritComponent: Transition,
mount,
refInstanceof: window.HTMLDivElement,
skip: ['componentProp'],
skip: [
'componentProp',
// react-transition-group issue
'reactTestRenderer',
],
}),
);

Expand Down
20 changes: 20 additions & 0 deletions packages/material-ui/src/test-utils/describeConformance.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { assert } from 'chai';
import React from 'react';
import findOutermostIntrinsic from './findOutermostIntrinsic';
import ReactTestRenderer from 'react-test-renderer';
import testRef from './testRef';

/**
Expand Down Expand Up @@ -146,12 +147,31 @@ function testRootClass(element, getOptions) {
});
}

/**
* Tests that the component can be rendered with react-test-renderer.
* This is important for snapshot testing with Jest (even if we don't encourage it).
*
* @param {React.ReactElement} element
*/
function testReactTestRenderer(element) {
it('should render without errors in ReactTestRenderer', () => {
ReactTestRenderer.act(() => {
ReactTestRenderer.create(element, {
createNodeMock: node => {
return document.createElement(node.type);
},
});
});
});
}

const fullSuite = {
componentProp: testComponentProp,
mergeClassName: testClassName,
propsSpread: testPropsSpread,
refForwarding: describeRef,
rootClass: testRootClass,
reactTestRenderer: testReactTestRenderer,
};

/**
Expand Down