Skip to content

Commit

Permalink
[test] Throw on console.(error|warn) outside of test (#22907)
Browse files Browse the repository at this point in the history
  • Loading branch information
eps1lon committed Oct 15, 2020
1 parent fcee9db commit 777c1a1
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 35 deletions.
80 changes: 49 additions & 31 deletions packages/material-ui/src/styles/experimentalStyled.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import ThemeProvider from './ThemeProvider';

describe('experimentalStyled', () => {
const render = createClientRender();

it('should work', () => {
const Div = styled('div')({
width: '200px',
Expand Down Expand Up @@ -52,43 +53,60 @@ describe('experimentalStyled', () => {
});

describe('muiOptions', () => {
const theme = createMuiTheme({
components: {
MuiTest: {
variants: [
{
props: { variant: 'rect', size: 'large' },
style: {
width: '400px',
height: '400px',
/**
* @type {ReturnType<typeof createMuiTheme>}
*/
let theme;
/**
* @type {ReturnType<typeof styled>}
*/
let Test;

before(() => {
theme = createMuiTheme({
components: {
MuiTest: {
variants: [
{
props: { variant: 'rect', size: 'large' },
style: {
width: '400px',
height: '400px',
},
},
],
styleOverrides: {
root: {
width: '250px',
},
rect: {
height: '250px',
},
},
],
styleOverrides: {
root: {
width: '250px',
},
rect: {
height: '250px',
},
},
},
},
});
});

const testOverridesResolver = (props, styles) => ({
...styles.root,
...(props.variant && styles[props.variant]),
});
const testOverridesResolver = (props, styles) => ({
...styles.root,
...(props.variant && styles[props.variant]),
});

const Test = styled(
'div',
{ shouldForwardProp: (prop) => prop !== 'variant' && prop !== 'size' },
{ muiName: 'MuiTest', overridesResolver: testOverridesResolver },
)`
width: 200px;
height: 300px;
`;
// FIXME: Should not error in DEV
expect(() => {
Test = styled(
'div',
{ shouldForwardProp: (prop) => prop !== 'variant' && prop !== 'size' },
{ muiName: 'MuiTest', overridesResolver: testOverridesResolver },
)`
width: 200px;
height: 300px;
`;
}).toErrorDev([
'You have illegal escape sequence in your template literal',
'You have illegal escape sequence in your template literal',
]);
});

it('should work with specified muiOptions', () => {
render(<Test data-testid="component">Test</Test>);
Expand Down
4 changes: 0 additions & 4 deletions test/utils/setupJSDOM.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,6 @@ function throwOnUnexpectedConsoleMessages(methodName, expectedMatcher) {
console[methodName] = logUnexpectedConsoleCalls;
});

mochaHooks.beforeEach.push(function resetUnexpectedCalls() {
unexpectedCalls.length = 0;
});

mochaHooks.afterEach.push(function flushUnexpectedCalls() {
const hadUnexpectedCalls = unexpectedCalls.length > 0;
const formattedCalls = unexpectedCalls.map(([stack, message]) => `${message}\n${stack}`);
Expand Down

0 comments on commit 777c1a1

Please sign in to comment.