Skip to content

Commit 49bb455

Browse files
authored
[test] Forward ref behavior (#15131)
* [test] Add `only` option to whitelist tests * [test] Add skip option to describeConformance * [Backdrop] Use describeConformance for ref forward test * [Box] Test ref forwarding * [FilledInput] Test ref forwarding * [Grid] Test ref forwarding * [Input] Test ref forwarding * [Menu] Use describeConformance for testRef * [MenuList] Use describeConformance for testRef * [NativeSelectInput] Test ref forwarding * [OutlinedInput] Test ref forwarding * [Popover] Test ref forwarding * [RadioGroup] Use describeConformance for testRef * [Select] Test ref forwarding * [StepIcon] Test ref forwarding * [Switch] Test ref forwarding * [TablePagination] Test forward ref
1 parent 877b286 commit 49bb455

File tree

16 files changed

+179
-47
lines changed

16 files changed

+179
-47
lines changed

packages/material-ui/src/Backdrop/Backdrop.test.js

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
import React from 'react';
22
import { assert } from 'chai';
3-
import { createMount, createShallow, getClasses, testRef } from '@material-ui/core/test-utils';
3+
import {
4+
createMount,
5+
createShallow,
6+
describeConformance,
7+
getClasses,
8+
} from '@material-ui/core/test-utils';
49
import Backdrop from './Backdrop';
510

611
describe('<Backdrop />', () => {
@@ -18,13 +23,15 @@ describe('<Backdrop />', () => {
1823
mount.cleanUp();
1924
});
2025

26+
describeConformance(<Backdrop open />, () => ({
27+
mount,
28+
only: ['refForwarding'],
29+
refInstanceof: window.HTMLDivElement,
30+
}));
31+
2132
it('should render a backdrop div', () => {
2233
const wrapper = shallow(<Backdrop open className="woofBackdrop" />);
2334
assert.strictEqual(wrapper.childAt(0).hasClass('woofBackdrop'), true);
2435
assert.strictEqual(wrapper.childAt(0).hasClass(classes.root), true);
2536
});
26-
27-
it('does forward refs', () => {
28-
testRef(<Backdrop open />, mount);
29-
});
3037
});

packages/material-ui/src/Box/Box.test.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React from 'react';
22
import { assert } from 'chai';
3-
import { createMount } from '@material-ui/core/test-utils';
3+
import { createMount, describeConformance } from '@material-ui/core/test-utils';
44
import Box from './Box';
55

66
describe('<Box />', () => {
@@ -14,6 +14,12 @@ describe('<Box />', () => {
1414
mount.cleanUp();
1515
});
1616

17+
describeConformance(<Box />, () => ({
18+
mount,
19+
only: ['refForwarding'],
20+
refInstanceof: window.HTMLDivElement,
21+
}));
22+
1723
const testChildren = <div className="unique">Hello World</div>;
1824

1925
it('renders children and box content', () => {

packages/material-ui/src/FilledInput/FilledInput.test.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
import React from 'react';
22
import { assert } from 'chai';
3-
import { createMount, findOutermostIntrinsic, getClasses } from '@material-ui/core/test-utils';
3+
import {
4+
createMount,
5+
describeConformance,
6+
findOutermostIntrinsic,
7+
getClasses,
8+
} from '@material-ui/core/test-utils';
49
import FilledInput from './FilledInput';
510

611
describe('<FilledInput />', () => {
@@ -16,6 +21,12 @@ describe('<FilledInput />', () => {
1621
mount.cleanUp();
1722
});
1823

24+
describeConformance(<FilledInput />, () => ({
25+
mount,
26+
only: ['refForwarding'],
27+
refInstanceof: window.HTMLDivElement,
28+
}));
29+
1930
it('should render a <div />', () => {
2031
const wrapper = mount(<FilledInput />);
2132
const root = findOutermostIntrinsic(wrapper);

packages/material-ui/src/Grid/Grid.test.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,30 @@
11
import React from 'react';
22
import { assert } from 'chai';
3-
import { createShallow, getClasses } from '@material-ui/core/test-utils';
3+
import {
4+
createMount,
5+
createShallow,
6+
describeConformance,
7+
getClasses,
8+
} from '@material-ui/core/test-utils';
49
import Grid from './Grid';
510

611
describe('<Grid />', () => {
12+
let mount;
713
let shallow;
814
let classes;
915

1016
before(() => {
17+
mount = createMount();
1118
shallow = createShallow({ dive: true });
1219
classes = getClasses(<Grid />);
1320
});
1421

22+
describeConformance(<Grid />, () => ({
23+
mount,
24+
only: ['refForwarding'],
25+
refInstanceof: window.HTMLDivElement,
26+
}));
27+
1528
it('should render', () => {
1629
const wrapper = shallow(<Grid className="woofGrid" />);
1730
assert.strictEqual(wrapper.name(), 'div');

packages/material-ui/src/Input/Input.test.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
import React from 'react';
22
import { assert } from 'chai';
3-
import { createMount, findOutermostIntrinsic } from '@material-ui/core/test-utils';
3+
import {
4+
createMount,
5+
describeConformance,
6+
findOutermostIntrinsic,
7+
} from '@material-ui/core/test-utils';
48
import Input from './Input';
59

610
describe('<Input />', () => {
@@ -14,6 +18,12 @@ describe('<Input />', () => {
1418
mount.cleanUp();
1519
});
1620

21+
describeConformance(<Input />, () => ({
22+
mount,
23+
only: ['refForwarding'],
24+
refInstanceof: window.HTMLDivElement,
25+
}));
26+
1727
it('should render a <div />', () => {
1828
const wrapper = mount(<Input />);
1929
assert.strictEqual(findOutermostIntrinsic(wrapper).type(), 'div');

packages/material-ui/src/Menu/Menu.test.js

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React from 'react';
22
import { spy } from 'sinon';
33
import { assert } from 'chai';
4-
import { createMount, getClasses, testRef } from '@material-ui/core/test-utils';
4+
import { createMount, describeConformance, getClasses } from '@material-ui/core/test-utils';
55
import Popover from '../Popover';
66
import Menu from './Menu';
77
import MenuList from '../MenuList';
@@ -11,13 +11,12 @@ const MENU_LIST_HEIGHT = 100;
1111
describe('<Menu />', () => {
1212
let classes;
1313
let mount;
14-
let defaultProps;
14+
const defaultProps = {
15+
open: false,
16+
anchorEl: () => document.createElement('div'),
17+
};
1518

1619
before(() => {
17-
defaultProps = {
18-
open: false,
19-
anchorEl: document.createElement('div'),
20-
};
2120
classes = getClasses(<Menu {...defaultProps} />);
2221
mount = createMount();
2322
});
@@ -26,9 +25,11 @@ describe('<Menu />', () => {
2625
mount.cleanUp();
2726
});
2827

29-
it('does forward refs', () => {
30-
testRef(<Menu {...defaultProps} open />, mount);
31-
});
28+
describeConformance(<Menu {...defaultProps} open />, () => ({
29+
mount,
30+
only: ['refForwarding'],
31+
refInstanceof: window.HTMLDivElement,
32+
}));
3233

3334
it('should render a Popover', () => {
3435
const wrapper = mount(<Menu {...defaultProps} />);

packages/material-ui/src/MenuList/MenuList.test.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React from 'react';
22
import { assert } from 'chai';
33
import { stub } from 'sinon';
4-
import { createMount, testRef } from '@material-ui/core/test-utils';
4+
import { createMount, describeConformance } from '@material-ui/core/test-utils';
55
import MenuList from './MenuList';
66
import getScrollbarSize from '../utils/getScrollbarSize';
77

@@ -26,9 +26,11 @@ describe('<MenuList />', () => {
2626
mount.cleanUp();
2727
});
2828

29-
it('does forward refs', () => {
30-
testRef(<MenuList />, mount);
31-
});
29+
describeConformance(<MenuList />, () => ({
30+
mount,
31+
only: ['refForwarding'],
32+
refInstanceof: window.HTMLUListElement,
33+
}));
3234

3335
describe('list node', () => {
3436
let wrapper;

packages/material-ui/src/NativeSelect/NativeSelectInput.test.js

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import React from 'react';
22
import { assert } from 'chai';
33
import { spy } from 'sinon';
4-
import { createShallow, createMount } from '@material-ui/core/test-utils';
5-
import MenuItem from '../MenuItem';
4+
import { createShallow, createMount, describeConformance } from '@material-ui/core/test-utils';
65
import NativeSelectInput from './NativeSelectInput';
76

87
describe('<NativeSelectInput />', () => {
@@ -13,15 +12,15 @@ describe('<NativeSelectInput />', () => {
1312
value: 10,
1413
IconComponent: 'div',
1514
children: [
16-
<MenuItem key={1} value={10}>
15+
<option key={1} value={10}>
1716
Ten
18-
</MenuItem>,
19-
<MenuItem key={2} value={20}>
17+
</option>,
18+
<option key={2} value={20}>
2019
Twenty
21-
</MenuItem>,
22-
<MenuItem key={3} value={30}>
20+
</option>,
21+
<option key={3} value={30}>
2322
Thirty
24-
</MenuItem>,
23+
</option>,
2524
],
2625
};
2726

@@ -34,6 +33,12 @@ describe('<NativeSelectInput />', () => {
3433
mount.cleanUp();
3534
});
3635

36+
describeConformance(<NativeSelectInput {...defaultProps} onChange={() => {}} />, () => ({
37+
mount,
38+
only: ['refForwarding'],
39+
refInstanceof: window.HTMLSelectElement,
40+
}));
41+
3742
it('should render a native select', () => {
3843
const wrapper = shallow(
3944
<NativeSelectInput {...defaultProps}>

packages/material-ui/src/OutlinedInput/OutlinedInput.test.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
import React from 'react';
22
import { assert } from 'chai';
3-
import { createMount, findOutermostIntrinsic } from '@material-ui/core/test-utils';
3+
import {
4+
createMount,
5+
describeConformance,
6+
findOutermostIntrinsic,
7+
} from '@material-ui/core/test-utils';
48
import OutlinedInput from './OutlinedInput';
59
import NotchedOutline from './NotchedOutline';
610

@@ -15,6 +19,12 @@ describe('<OutlinedInput />', () => {
1519
mount.cleanUp();
1620
});
1721

22+
describeConformance(<OutlinedInput labelWidth={0} />, () => ({
23+
mount,
24+
only: ['refForwarding'],
25+
refInstanceof: window.HTMLDivElement,
26+
}));
27+
1828
it('should render a <div />', () => {
1929
const wrapper = mount(<OutlinedInput labelWidth={0} />);
2030
assert.strictEqual(findOutermostIntrinsic(wrapper).type(), 'div');

packages/material-ui/src/Popover/Popover.test.js

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import PropTypes from 'prop-types';
55
import {
66
createShallow,
77
createMount,
8+
describeConformance,
89
findOutermostIntrinsic,
910
getClasses,
1011
} from '@material-ui/core/test-utils';
@@ -18,7 +19,10 @@ describe('<Popover />', () => {
1819
let shallow;
1920
let mount;
2021
let classes;
21-
let defaultProps;
22+
const defaultProps = {
23+
open: false,
24+
anchorEl: () => document.createElement('div'),
25+
};
2226

2327
before(() => {
2428
shallow = createShallow({ dive: true });
@@ -28,16 +32,18 @@ describe('<Popover />', () => {
2832
<div />
2933
</Popover>,
3034
);
31-
defaultProps = {
32-
open: false,
33-
anchorEl: document.createElement('div'),
34-
};
3535
});
3636

3737
after(() => {
3838
mount.cleanUp();
3939
});
4040

41+
describeConformance(<Popover {...defaultProps} open />, () => ({
42+
mount,
43+
only: ['refForwarding'],
44+
refInstanceof: window.HTMLDivElement,
45+
}));
46+
4147
describe('root node', () => {
4248
it('should render a Modal with an invisible backdrop as the root node', () => {
4349
const wrapper = mount(

0 commit comments

Comments
 (0)