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] Add StrictMode compat layer test #20547

Merged
merged 1 commit into from
Apr 14, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
44 changes: 43 additions & 1 deletion packages/material-ui/src/ListItem/ListItem.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const NoContent = React.forwardRef(() => {

describe('<ListItem />', () => {
let mount;
const render = createClientRender({ strict: false });
const render = createClientRender();
let classes;

before(() => {
Expand Down Expand Up @@ -126,6 +126,21 @@ describe('<ListItem />', () => {
expect(listItem.querySelector(`div.${classes.root}`)).not.to.equal(null);
});

it('can autofocus a custom ContainerComponent', () => {
const { getByRole } = render(
<ListItem
autoFocus
ContainerComponent="div"
ContainerProps={{ role: 'listitem', tabIndex: -1 }}
>
<ListItemText primary="primary" />
<ListItemSecondaryAction />
</ListItem>,
);

expect(getByRole('listitem')).toHaveFocus();
});

it('should allow customization of the wrapper', () => {
const { getByRole } = render(
<ListItem ContainerProps={{ className: 'bubu', role: 'listitem' }}>
Expand Down Expand Up @@ -177,6 +192,33 @@ describe('<ListItem />', () => {
'Material-UI: unable to set focus to a ListItem whose component has not been rendered.',
);
});

// StrictMode compatible usage is illustrated in "can autofocus a custom ContainerComponent"
it('warns in StrictMode if the custom ContainerComponent is a class component', () => {
// eslint-disable-next-line react/prefer-stateless-function
class CustomListItemContainer extends React.Component {
// React dedupes the findDOMNode deprecation warning by displayName
// since we can't reset modules in watchmode we implement cache busting
// by creating a random display name
static displayName = `CustomListItemContainer-#${Math.random()}`;

render() {
return <div role="listitem" tabIndex={-1} {...this.props} />;
}
}
const { getByRole } = render(
<ListItem autoFocus ContainerComponent={CustomListItemContainer}>
<ListItemText primary="primary" />
<ListItemSecondaryAction />
</ListItem>,
);

expect(getByRole('listitem')).toHaveFocus();
expect(consoleErrorMock.callCount()).to.equal(1);
expect(consoleErrorMock.messages()[0]).to.include(
'findDOMNode is deprecated in StrictMode',
);
});
});
});

Expand Down