Skip to content

Commit

Permalink
move resetWarningCache to beforeEach
Browse files Browse the repository at this point in the history
Otherwise tests could work without resetWarningCache
because another test ran before them that reset the cache
  • Loading branch information
eps1lon committed Apr 7, 2020
1 parent e751e90 commit b6f44b7
Show file tree
Hide file tree
Showing 16 changed files with 16 additions and 20 deletions.
2 changes: 1 addition & 1 deletion packages/material-ui-styles/src/styled/styled.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,11 @@ describe('styled', () => {
describe('warnings', () => {
beforeEach(() => {
consoleErrorMock.spy();
PropTypes.resetWarningCache();
});

afterEach(() => {
consoleErrorMock.reset();
PropTypes.resetWarningCache();
});

it('warns if it cant detect the secondary action properly', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,11 @@ describe('withStyles', () => {
// describe('innerRef', () => {
// beforeEach(() => {
// consoleErrorMock.spy();
// PropTypes.resetWarningCache();
// });

// afterEach(() => {
// consoleErrorMock.reset();
// PropTypes.resetWarningCache();
// });

// it('is deprecated', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,11 @@ describe('withTheme', () => {
describe('innerRef', () => {
beforeEach(() => {
consoleErrorMock.spy();
PropTypes.resetWarningCache();
});

afterEach(() => {
consoleErrorMock.reset();
PropTypes.resetWarningCache();
});

it('is deprecated', () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/material-ui-utils/src/elementAcceptingRef.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ describe('elementAcceptingRef', () => {

beforeEach(() => {
consoleErrorMock.spy();
PropTypes.resetWarningCache();
});

afterEach(() => {
consoleErrorMock.reset();
PropTypes.resetWarningCache();
});

describe('acceptance when not required', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ describe('elementTypeAcceptingRef', () => {

beforeEach(() => {
consoleErrorMock.spy();
PropTypes.resetWarningCache();
});

afterEach(() => {
consoleErrorMock.reset();
PropTypes.resetWarningCache();
});

describe('acceptance', () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/material-ui/src/ButtonBase/ButtonBase.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -908,11 +908,11 @@ describe('<ButtonBase />', () => {
describe('warnings', () => {
beforeEach(() => {
consoleErrorMock.spy();
PropTypes.resetWarningCache();
});

afterEach(() => {
consoleErrorMock.reset();
PropTypes.resetWarningCache();
});

it('warns on invalid `component` prop: ref forward', () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/material-ui/src/CardMedia/CardMedia.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,11 @@ describe('<CardMedia />', () => {
describe('warnings', () => {
before(() => {
consoleErrorMock.spy();
PropTypes.resetWarningCache();
});

after(() => {
consoleErrorMock.reset();
PropTypes.resetWarningCache();
});

it('warns when neither `children`, nor `image`, nor `src`, nor `component` are provided', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,11 +137,11 @@ describe('<ExpansionPanel />', () => {
describe('first child', () => {
beforeEach(() => {
consoleErrorMock.spy();
PropTypes.resetWarningCache();
});

afterEach(() => {
consoleErrorMock.reset();
PropTypes.resetWarningCache();
});

it('requires at least one child', () => {
Expand Down
2 changes: 0 additions & 2 deletions packages/material-ui/src/GridList/GridList.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { createMount, createShallow, getClasses } from '@material-ui/core/test-u
import describeConformance from '../test-utils/describeConformance';
import GridList from './GridList';
import consoleErrorMock from 'test/utils/consoleErrorMock';
import PropTypes from 'prop-types';

const tilesData = [
{
Expand Down Expand Up @@ -181,7 +180,6 @@ describe('<GridList />', () => {

after(() => {
consoleErrorMock.reset();
PropTypes.resetWarningCache();
});

it('warns a Fragment is passed as a child', () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/material-ui/src/IconButton/IconButton.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,11 +128,11 @@ describe('<IconButton />', () => {
describe('Firefox onClick', () => {
beforeEach(() => {
consoleErrorMock.spy();
PropTypes.resetWarningCache();
});

afterEach(() => {
consoleErrorMock.reset();
PropTypes.resetWarningCache();
});

it('should raise a warning', () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/material-ui/src/ListItem/ListItem.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,11 +142,11 @@ describe('<ListItem />', () => {
describe('warnings', () => {
beforeEach(() => {
consoleErrorMock.spy();
PropTypes.resetWarningCache();
});

afterEach(() => {
consoleErrorMock.reset();
PropTypes.resetWarningCache();
});

it('warns if it cant detect the secondary action properly', () => {
Expand Down
2 changes: 0 additions & 2 deletions packages/material-ui/src/Menu/Menu.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import Popover from '../Popover';
import Menu from './Menu';
import MenuList from '../MenuList';
import consoleErrorMock from 'test/utils/consoleErrorMock';
import PropTypes from 'prop-types';

const MENU_LIST_HEIGHT = 100;

Expand Down Expand Up @@ -233,7 +232,6 @@ describe('<Menu />', () => {

after(() => {
consoleErrorMock.reset();
PropTypes.resetWarningCache();
});

it('warns a Fragment is passed as a child', () => {
Expand Down
2 changes: 0 additions & 2 deletions packages/material-ui/src/Popover/Popover.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import * as React from 'react';
import { assert, expect } from 'chai';
import { spy, stub, useFakeTimers } from 'sinon';
import PropTypes from 'prop-types';
import { createMount, findOutermostIntrinsic, getClasses } from '@material-ui/core/test-utils';
import describeConformance from '../test-utils/describeConformance';
import consoleErrorMock from 'test/utils/consoleErrorMock';
Expand Down Expand Up @@ -461,7 +460,6 @@ describe('<Popover />', () => {
describe('warnings', () => {
beforeEach(() => {
consoleErrorMock.spy();
PropTypes.resetWarningCache();
});

afterEach(() => {
Expand Down
2 changes: 1 addition & 1 deletion packages/material-ui/src/Slider/Slider.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -489,11 +489,11 @@ describe('<Slider />', () => {
describe('warnings', () => {
beforeEach(() => {
consoleErrorMock.spy();
PropTypes.resetWarningCache();
});

afterEach(() => {
consoleErrorMock.reset();
PropTypes.resetWarningCache();
});

it('should warn if aria-valuetext is provided', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -280,15 +280,14 @@ describe('<TablePagination />', () => {
describe('warnings', () => {
before(() => {
consoleErrorMock.spy();
PropTypes.resetWarningCache();
});

after(() => {
consoleErrorMock.reset();
PropTypes.resetWarningCache();
});

it('should raise a warning if the page prop is out of range', () => {
assert.strictEqual(consoleErrorMock.callCount(), 0);
mount(
<table>
<TableFooter>
Expand All @@ -304,6 +303,7 @@ describe('<TablePagination />', () => {
</TableFooter>
</table>,
);

assert.strictEqual(consoleErrorMock.callCount(), 1);
assert.include(
consoleErrorMock.messages()[0],
Expand Down
4 changes: 3 additions & 1 deletion packages/material-ui/src/useMediaQuery/useMediaQuery.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,6 @@ describe('useMediaQuery', () => {

afterEach(() => {
consoleErrorMock.reset();
PropTypes.resetWarningCache();
});

it('warns on invalid `query` argument', () => {
Expand All @@ -285,7 +284,10 @@ describe('useMediaQuery', () => {
}

render(<MyComponent />);
// logs warning twice in StrictMode
expect(consoleErrorMock.callCount()).to.equal(2);
expect(consoleErrorMock.messages()[0]).to.include('the `query` argument provided is invalid');
expect(consoleErrorMock.messages()[1]).to.include('the `query` argument provided is invalid');
});
});
});

0 comments on commit b6f44b7

Please sign in to comment.