Skip to content

Commit

Permalink
[test] Migrate from assert to expect
Browse files Browse the repository at this point in the history
  • Loading branch information
oliviertassinari committed Apr 27, 2020
1 parent a8afd1e commit 878d6a3
Show file tree
Hide file tree
Showing 116 changed files with 1,626 additions and 1,876 deletions.
16 changes: 8 additions & 8 deletions docs/src/modules/utils/helpers.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { assert } from 'chai';
import { expect } from 'chai';
import { getDependencies } from './helpers';

describe('docs getDependencies helpers', () => {
Expand All @@ -21,7 +21,7 @@ const styles = theme => ({
`;

it('should handle @ dependencies', () => {
assert.deepEqual(getDependencies(s1), {
expect(getDependencies(s1)).to.deep.equal({
'@foo-bar/bip': 'latest',
'@material-ui/core': 'latest',
'prop-types': 'latest',
Expand All @@ -45,7 +45,7 @@ import { withStyles } from '@material-ui/core/styles';
const suggestions = [
`;

assert.deepEqual(getDependencies(source), {
expect(getDependencies(source)).to.deep.equal({
'@material-ui/core': 'latest',
'@unexisting/thing': 'latest',
'autosuggest-highlight': 'latest',
Expand All @@ -57,7 +57,7 @@ const suggestions = [
});

it('should support next dependencies', () => {
assert.deepEqual(getDependencies(s1, { reactVersion: 'next' }), {
expect(getDependencies(s1, { reactVersion: 'next' })).to.deep.equal({
'@foo-bar/bip': 'latest',
'@material-ui/core': 'latest',
'prop-types': 'latest',
Expand All @@ -77,7 +77,7 @@ import DateFnsUtils from '@date-io/date-fns';
import { MuiPickersUtilsProvider, TimePicker, DatePicker } from '@material-ui/pickers';
`;

assert.deepEqual(getDependencies(source), {
expect(getDependencies(source)).to.deep.equal({
'date-fns': 'latest',
'@date-io/date-fns': 'v1',
'@material-ui/pickers': 'latest',
Expand All @@ -89,7 +89,7 @@ import { MuiPickersUtilsProvider, TimePicker, DatePicker } from '@material-ui/pi
});

it('can collect required @types packages', () => {
assert.deepEqual(getDependencies(s1, { codeLanguage: 'TS' }), {
expect(getDependencies(s1, { codeLanguage: 'TS' })).to.deep.equal({
'@foo-bar/bip': 'latest',
'@material-ui/core': 'latest',
'prop-types': 'latest',
Expand All @@ -114,7 +114,7 @@ import {
} from '@material-ui/pickers';
`;

assert.deepEqual(getDependencies(source), {
expect(getDependencies(source)).to.deep.equal({
'date-fns': 'latest',
'@material-ui/pickers': 'latest',
react: 'latest',
Expand All @@ -127,7 +127,7 @@ import {
import lab from '@material-ui/lab';
`;

assert.deepEqual(getDependencies(source), {
expect(getDependencies(source)).to.deep.equal({
'@material-ui/core': 'latest',
'@material-ui/lab': 'latest',
react: 'latest',
Expand Down
27 changes: 12 additions & 15 deletions packages/material-ui-icons/builder.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { assert } from 'chai';
import { expect, assert } from 'chai';
import fs from 'fs';
import path from 'path';
import temp from 'temp';
Expand All @@ -22,16 +22,16 @@ describe('builder', () => {

describe('#getComponentName', () => {
it('should change capitalize dashes', () => {
assert.strictEqual(getComponentName('hi-world'), 'HiWorld', true);
expect(getComponentName('hi-world')).to.equal('HiWorld');
});

it('should capitalize based on environment path.sep', () => {
assert.strictEqual(getComponentName(`this${path.sep}dir`), 'ThisDir', true);
expect(getComponentName(`this${path.sep}dir`)).to.equal('ThisDir');
});
});

it('should have icons to test with', () => {
assert.strictEqual(fs.lstatSync(MUI_ICONS_SVG_DIR).isDirectory(), true);
expect(fs.lstatSync(MUI_ICONS_SVG_DIR).isDirectory()).to.equal(true);
});

it('should have main', () => {
Expand All @@ -58,8 +58,8 @@ describe('builder', () => {

it('script outputs to directory', async () => {
await main(options);
assert.strictEqual(fs.lstatSync(options.outputDir).isDirectory(), true);
assert.strictEqual(fs.lstatSync(path.join(options.outputDir, 'index.js')).isFile(), true);
expect(fs.lstatSync(options.outputDir).isDirectory()).to.equal(true);
expect(fs.lstatSync(path.join(options.outputDir, 'index.js')).isFile()).to.equal(true);
});
});

Expand All @@ -83,11 +83,8 @@ describe('builder', () => {

it('script outputs to directory', async () => {
await main(options);
assert.strictEqual(fs.lstatSync(options.outputDir).isDirectory(), true);
assert.strictEqual(
fs.lstatSync(path.join(options.outputDir, 'delapouite')).isDirectory(),
true,
);
expect(fs.lstatSync(options.outputDir).isDirectory()).to.equal(true);
expect(fs.lstatSync(path.join(options.outputDir, 'delapouite')).isDirectory()).to.equal(true);

const actualFilePath = path.join(
options.outputDir,
Expand All @@ -98,10 +95,10 @@ describe('builder', () => {
'transparent',
'Dice-six-faces-four.js',
);
assert.strictEqual(fs.existsSync(actualFilePath), true);
expect(fs.existsSync(actualFilePath)).to.equal(true);

const actualFileData = fs.readFileSync(actualFilePath, { encoding: 'utf8' });
assert.include(actualFileData, "import createSvgIcon from './utils/createSvgIcon'");
expect(actualFileData).to.include("import createSvgIcon from './utils/createSvgIcon'");
});
});

Expand All @@ -125,7 +122,7 @@ describe('builder', () => {

it('should produce the expected output', async () => {
await main(options);
assert.strictEqual(fs.lstatSync(options.outputDir).isDirectory(), true);
expect(fs.lstatSync(options.outputDir).isDirectory()).to.equal(true);

const cases = [
'Accessibility.js',
Expand All @@ -143,7 +140,7 @@ describe('builder', () => {
encoding: 'utf8',
});

assert.include(actual, expected);
expect(actual).to.include(expected);
});
});
});
Expand Down
35 changes: 15 additions & 20 deletions packages/material-ui-lab/src/SpeedDial/SpeedDial.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as React from 'react';
import { assert } from 'chai';
import { expect } from 'chai';
import { spy } from 'sinon';
import {
createMount,
Expand Down Expand Up @@ -56,7 +56,7 @@ describe('<SpeedDial />', () => {
<FakeAction />
</SpeedDial>,
);
assert.strictEqual(findOutermostIntrinsic(wrapper).type(), 'div');
expect(findOutermostIntrinsic(wrapper).type()).to.equal('div');
});

it('should render a Fab', () => {
Expand All @@ -66,7 +66,7 @@ describe('<SpeedDial />', () => {
</SpeedDial>,
);
const buttonWrapper = wrapper.find('[aria-expanded]').first();
assert.strictEqual(buttonWrapper.type(), Fab);
expect(buttonWrapper.type()).to.equal(Fab);
});

it('should render with a null child', () => {
Expand All @@ -77,7 +77,7 @@ describe('<SpeedDial />', () => {
<SpeedDialAction icon={icon} tooltipTitle="Three" />
</SpeedDial>,
);
assert.strictEqual(wrapper.find(SpeedDialAction).length, 2);
expect(wrapper.find(SpeedDialAction).length).to.equal(2);
});

it('should pass the open prop to its children', () => {
Expand All @@ -89,7 +89,7 @@ describe('<SpeedDial />', () => {
</SpeedDial>,
);
const actions = wrapper.find('[role="menuitem"]').filterWhere(wrapsIntrinsicElement);
assert.strictEqual(actions.some('.is-closed'), false);
expect(actions.some('.is-closed')).to.equal(false);
});

describe('prop: onKeyDown', () => {
Expand All @@ -106,8 +106,8 @@ describe('<SpeedDial />', () => {
key: ' ',
eventMock,
});
assert.strictEqual(handleKeyDown.callCount, 1);
assert.strictEqual(handleKeyDown.calledWithMatch({ eventMock }), true);
expect(handleKeyDown.callCount).to.equal(1);
expect(handleKeyDown.calledWithMatch({ eventMock })).to.equal(true);
});
});

Expand All @@ -120,7 +120,7 @@ describe('<SpeedDial />', () => {
<SpeedDialAction icon={icon} tooltipTitle="action2" />
</SpeedDial>,
);
assert.strictEqual(findOutermostIntrinsic(wrapper).hasClass(classes[className]), true);
expect(findOutermostIntrinsic(wrapper).hasClass(classes[className])).to.equal(true);
};

it('should place actions in correct position', () => {
Expand Down Expand Up @@ -204,20 +204,20 @@ describe('<SpeedDial />', () => {

it('displays the actions on focus gain', () => {
resetDialToOpen();
assert.strictEqual(wrapper.find(SpeedDial).props().open, true);
expect(wrapper.find(SpeedDial).props().open).to.equal(true);
});

describe('first item selection', () => {
it('considers arrow keys with the same initial orientation', () => {
resetDialToOpen();
getDialButton().simulate('keydown', { key: 'left' });
assert.strictEqual(isActionFocused(0), true);
expect(isActionFocused(0)).to.equal(true);
getDialButton().simulate('keydown', { key: 'up' });
assert.strictEqual(isActionFocused(0), true);
expect(isActionFocused(0)).to.equal(true);
getDialButton().simulate('keydown', { key: 'left' });
assert.strictEqual(isActionFocused(1), true);
expect(isActionFocused(1)).to.equal(true);
getDialButton().simulate('keydown', { key: 'right' });
assert.strictEqual(isActionFocused(0), true);
expect(isActionFocused(0)).to.equal(true);
});
});

Expand All @@ -236,11 +236,7 @@ describe('<SpeedDial />', () => {
resetDialToOpen(dialDirection);

getDialButton().simulate('keydown', { key: firstKey });
assert.strictEqual(
isActionFocused(firstFocusedAction),
true,
`focused action initial ${firstKey} should be ${firstFocusedAction}`,
);
expect(isActionFocused(firstFocusedAction)).to.equal(true);

combination.forEach((arrowKey, i) => {
const previousFocusedAction = foci[i - 1] || firstFocusedAction;
Expand All @@ -250,8 +246,7 @@ describe('<SpeedDial />', () => {
getActionButton(previousFocusedAction).simulate('keydown', {
key: arrowKey,
});
assert.strictEqual(
isActionFocused(expectedFocusedAction),
expect(isActionFocused(expectedFocusedAction)).to.equal(
true,
`focused action after ${combinationUntilNot.join(
',',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as React from 'react';
import { assert } from 'chai';
import { expect } from 'chai';
import { createMount, getClasses } from '@material-ui/core/test-utils';
import Icon from '@material-ui/core/Icon';
import Tooltip from '@material-ui/core/Tooltip';
Expand Down Expand Up @@ -38,24 +38,24 @@ describe('<SpeedDialAction />', () => {
const wrapper = mount(
<SpeedDialAction {...defaultProps} TooltipClasses={{ tooltip: 'bar' }} />,
);
assert.include(wrapper.find(Tooltip).props().classes.tooltip, 'bar');
expect(wrapper.find(Tooltip).props().classes.tooltip).to.include('bar');
});

it('should render a Fab', () => {
const wrapper = mount(<SpeedDialAction {...defaultProps} />);
assert.strictEqual(wrapper.find(Fab).exists(), true);
expect(wrapper.find(Fab).exists()).to.equal(true);
});

it('should render the button with the fab class', () => {
const wrapper = mount(<SpeedDialAction {...defaultProps} open />);
const buttonWrapper = wrapper.find('button');
assert.strictEqual(buttonWrapper.hasClass(classes.fab), true);
expect(buttonWrapper.hasClass(classes.fab)).to.equal(true);
});

it('should render the button with the fab and fabClosed classes', () => {
const wrapper = mount(<SpeedDialAction {...defaultProps} />);
const buttonWrapper = wrapper.find('button');
assert.strictEqual(buttonWrapper.hasClass(classes.fab), true);
assert.strictEqual(buttonWrapper.hasClass(classes.fabClosed), true);
expect(buttonWrapper.hasClass(classes.fab)).to.equal(true);
expect(buttonWrapper.hasClass(classes.fabClosed)).to.equal(true);
});
});
37 changes: 17 additions & 20 deletions packages/material-ui-lab/src/SpeedDialIcon/SpeedDialIcon.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as React from 'react';
import { assert } from 'chai';
import { expect } from 'chai';
import { createMount, getClasses, findOutermostIntrinsic } from '@material-ui/core/test-utils';
import Icon from '@material-ui/core/Icon';
import SpeedDialIcon from './SpeedDialIcon';
Expand Down Expand Up @@ -29,59 +29,56 @@ describe('<SpeedDialIcon />', () => {

it('should render the Add icon by default', () => {
const wrapper = mount(<SpeedDialIcon />);
assert.strictEqual(
findOutermostIntrinsic(wrapper).find('svg[data-mui-test="AddIcon"]').length,
1,
);
expect(findOutermostIntrinsic(wrapper).find('svg[data-mui-test="AddIcon"]').length).to.equal(1);
});

it('should render an Icon', () => {
const wrapper = mount(<SpeedDialIcon icon={icon} />);
const iconWrapper = findOutermostIntrinsic(wrapper).childAt(0);
assert.strictEqual(iconWrapper.find(Icon).length, 1);
expect(iconWrapper.find(Icon).length).to.equal(1);
});

it('should render an openIcon', () => {
const wrapper = mount(<SpeedDialIcon openIcon={icon} />);
const iconWrapper = findOutermostIntrinsic(wrapper).childAt(0);
assert.strictEqual(iconWrapper.find(Icon).length, 1);
expect(iconWrapper.find(Icon).length).to.equal(1);
});

it('should render the icon with the icon class', () => {
const wrapper = mount(<SpeedDialIcon />);
const iconWrapper = findOutermostIntrinsic(wrapper).childAt(0);
assert.strictEqual(iconWrapper.hasClass(classes.icon), true);
assert.strictEqual(iconWrapper.hasClass(classes.iconOpen), false);
assert.strictEqual(iconWrapper.hasClass(classes.iconWithOpenIconOpen), false);
expect(iconWrapper.hasClass(classes.icon)).to.equal(true);
expect(iconWrapper.hasClass(classes.iconOpen)).to.equal(false);
expect(iconWrapper.hasClass(classes.iconWithOpenIconOpen)).to.equal(false);
});

it('should render the icon with the icon and iconOpen classes', () => {
const wrapper = mount(<SpeedDialIcon open />);
const iconWrapper = findOutermostIntrinsic(wrapper).childAt(0);
assert.strictEqual(iconWrapper.hasClass(classes.icon), true);
assert.strictEqual(iconWrapper.hasClass(classes.iconOpen), true);
assert.strictEqual(iconWrapper.hasClass(classes.iconWithOpenIconOpen), false);
expect(iconWrapper.hasClass(classes.icon)).to.equal(true);
expect(iconWrapper.hasClass(classes.iconOpen)).to.equal(true);
expect(iconWrapper.hasClass(classes.iconWithOpenIconOpen)).to.equal(false);
});

it('should render the icon with the icon, iconOpen iconWithOpenIconOpen classes', () => {
const wrapper = mount(<SpeedDialIcon open openIcon={icon} />);
const iconWrapper = findOutermostIntrinsic(wrapper).childAt(1);
assert.strictEqual(iconWrapper.hasClass(classes.icon), true);
assert.strictEqual(iconWrapper.hasClass(classes.iconOpen), true);
assert.strictEqual(iconWrapper.hasClass(classes.iconWithOpenIconOpen), true);
expect(iconWrapper.hasClass(classes.icon)).to.equal(true);
expect(iconWrapper.hasClass(classes.iconOpen)).to.equal(true);
expect(iconWrapper.hasClass(classes.iconWithOpenIconOpen)).to.equal(true);
});

it('should render the openIcon with the openIcon class', () => {
const wrapper = mount(<SpeedDialIcon openIcon={icon} />);
const iconWrapper = findOutermostIntrinsic(wrapper).childAt(0);
assert.strictEqual(iconWrapper.hasClass(classes.openIcon), true);
assert.strictEqual(iconWrapper.hasClass(classes.openIconOpen), false);
expect(iconWrapper.hasClass(classes.openIcon)).to.equal(true);
expect(iconWrapper.hasClass(classes.openIconOpen)).to.equal(false);
});

it('should render the openIcon with the openIcon, openIconOpen classes', () => {
const wrapper = mount(<SpeedDialIcon open openIcon={icon} />);
const iconWrapper = findOutermostIntrinsic(wrapper).childAt(0);
assert.strictEqual(iconWrapper.hasClass(classes.openIcon), true);
assert.strictEqual(iconWrapper.hasClass(classes.openIconOpen), true);
expect(iconWrapper.hasClass(classes.openIcon)).to.equal(true);
expect(iconWrapper.hasClass(classes.openIconOpen)).to.equal(true);
});
});
Loading

0 comments on commit 878d6a3

Please sign in to comment.