Skip to content

Commit

Permalink
[styles] Outdated warning message (#25637)
Browse files Browse the repository at this point in the history
Co-authored-by: Olivier Tassinari <[email protected]>
  • Loading branch information
bhairavee23 and oliviertassinari authored Apr 7, 2021
1 parent e4917cb commit d520cfc
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export default function getStylesCreator(stylesOrCreator) {
console.warn(
[
'Material-UI: You are trying to override a style that does not exist.',
`Fix the \`${key}\` key of \`theme.overrides.${name}\`.`,
`Fix the \`${key}\` key of \`theme.components.${name}.styleOverrides\`.`,
'',
`If you intentionally wanted to add a new key, please use the theme.components[${name}].variants option.`,
].join('\n'),
Expand Down
31 changes: 31 additions & 0 deletions packages/material-ui-styles/src/makeStyles/makeStyles.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,37 @@ describe('makeStyles', () => {
mountWithProps2({});
}).not.to.throw();
});

it('should warn if the key is not available', () => {
const theme = {
components: {
Test: {
styleOverrides: {
foo: {
margin: '1px',
},
},
},
},
};

const useStyles = makeStyles({ root: { margin: 5, padding: 3 } }, { name: 'Test' });
function Test() {
const classes = useStyles();
return <div className={classes.root} />;
}

expect(() => {
mount(
<ThemeProvider theme={theme}>
<Test />
</ThemeProvider>,
);
}).toWarnDev([
'Material-UI: You are trying to override a style that does not exist.\n' +
'Fix the `foo` key of `theme.components.Test.styleOverrides`.',
]);
});
});

describe('classes memoization', () => {
Expand Down

0 comments on commit d520cfc

Please sign in to comment.