Skip to content

Commit

Permalink
[test] Remove all assert.x API
Browse files Browse the repository at this point in the history
  • Loading branch information
oliviertassinari committed May 9, 2020
1 parent ad9e3eb commit a528ab4
Show file tree
Hide file tree
Showing 10 changed files with 27 additions and 87 deletions.
29 changes: 1 addition & 28 deletions packages/material-ui-styles/src/withStyles/withStyles.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ describe('withStyles', () => {

const ref = React.createRef();
mount(<StyledTarget ref={ref} />);
assert.instanceOf(ref.current, TargetComponent);
expect(ref.current instanceof TargetComponent).to.equal(true);
});

it('forwards refs to React.forwardRef types', () => {
Expand All @@ -69,33 +69,6 @@ describe('withStyles', () => {
mount(<StyledTarget ref={ref} />);
expect(ref.current.nodeName).to.equal('DIV');
});

// describe('innerRef', () => {
// beforeEach(() => {
// consoleErrorMock.spy();
// PropTypes.resetWarningCache();
// });

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

// it('is deprecated', () => {
// const ThemedDiv = withStyles({})('div');

// mount(
// <React.Fragment>
// <ThemedDiv innerRef={React.createRef()} />
// </React.Fragment>,
// );

// assert.strictEqual(consoleErrorMock.callCount(), 1);
// assert.include(
// consoleErrorMock.messages()[0],
// 'Warning: Failed prop type: Material-UI: The `innerRef` prop is deprecated',
// );
// });
// });
});

it('should forward the props', () => {
Expand Down
14 changes: 0 additions & 14 deletions packages/material-ui-system/src/spacing.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,20 +142,6 @@ describe('spacing', () => {
padding: 16,
},
});

// const output3 = spacing({
// theme: {},
// p: 1,
// sm: {
// p: 2,
// },
// });
// assert.deepEqual(output3, {
// padding: 8,
// '@media (min-width:600px)': {
// padding: 16,
// },
// });
});

it('should support full version', () => {
Expand Down
14 changes: 0 additions & 14 deletions packages/material-ui-system/src/style.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,20 +47,6 @@ describe('style', () => {
backgroundColor: 'red',
},
});

// const output3 = bgcolor({
// theme: {},
// bgcolor: 'blue',
// sm: {
// bgcolor: 'red',
// },
// });
// assert.deepEqual(output3, {
// backgroundColor: 'blue',
// '@media (min-width:600px)': {
// backgroundColor: 'red',
// },
// });
});

const boxShadow = style({
Expand Down
6 changes: 0 additions & 6 deletions packages/material-ui/src/Popover/Popover.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -465,12 +465,6 @@ describe('<Popover />', () => {
'Warning: Failed prop type: Invalid prop `PaperProps.component` supplied to `MockedPopover`. Expected an element type that can hold a ref.',
);
});

// it('should warn if anchorEl is not visible', () => {
// mount(<Popover open anchorEl={document.createElement('div')} />);
// assert.strictEqual(consoleErrorMock.callCount(), 1);
// assert.include(consoleErrorMock.messages()[0], 'The node element should be visible');
// });
});

describe('prop anchorReference="anchorPosition"', () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/material-ui/src/Tabs/Tabs.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ describe('<Tabs />', () => {
// The test fails on Safari with just:
//
// container.scrollLeft = 200;
// assert.strictEqual(container.scrollLeft, 200); 💥
// expect(container.scrollLeft).to.equal(200); 💥
if (isSafari) {
return;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/material-ui/src/internal/animate.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ describe('animate', () => {
// The test fails on Safari with just:
//
// container.scrollLeft = 200;
// assert.strictEqual(container.scrollLeft, 200); 💥
// expect(container.scrollLeft).to.equal(200); 💥

// in JSDOM the test prevents mocha from exiting
this.skip();
Expand Down
19 changes: 10 additions & 9 deletions packages/material-ui/src/test-utils/describeConformance.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { assert } from 'chai';
import { expect } from 'chai';
import * as React from 'react';
import findOutermostIntrinsic from './findOutermostIntrinsic';
import ReactTestRenderer from 'react-test-renderer';
Expand Down Expand Up @@ -47,8 +47,9 @@ function testClassName(element, getOptions) {

const wrapper = mount(React.cloneElement(element, { className }));

assert.strictEqual(
findOutermostIntrinsic(wrapper).hasClass(className),
expect(
findOutermostIntrinsic(wrapper).hasClass(className)
).to.equal(
true,
'does have a custom `className`',
);
Expand All @@ -69,7 +70,7 @@ function testComponentProp(element, getOptions) {

const wrapper = mount(React.cloneElement(element, { component }));

assert.strictEqual(findRootComponent(wrapper, { classes, component }).exists(), true);
expect(findRootComponent(wrapper, { classes, component }).exists()).to.equal(true);
});
});
}
Expand All @@ -91,7 +92,7 @@ function testPropsSpread(element, getOptions) {
const wrapper = mount(React.cloneElement(element, { [testProp]: value }));
const root = findRootComponent(wrapper, { classes, component: inheritComponent });

assert.strictEqual(root.props()[testProp], value);
expect(root.props()[testProp]).to.equal(value);
});
}

Expand All @@ -111,11 +112,11 @@ function describeRef(element, getOptions) {
const { inheritComponent, mount, refInstanceof } = getOptions();

testRef(element, mount, (instance, wrapper) => {
assert.instanceOf(instance, refInstanceof);
expect(instance instanceof refInstanceof).to.equal(true);

if (inheritComponent && instance.nodeType === 1) {
const rootHost = findOutermostIntrinsic(wrapper);
assert.strictEqual(instance, rootHost.instance());
expect(instance).to.equal(rootHost.instance());
}
});
});
Expand All @@ -142,8 +143,8 @@ function testRootClass(element, getOptions) {
// jump to the host component because some components pass the `root` class
// to the `classes` prop of the root component.
// https://github.com/mui-org/material-ui/blob/f9896bcd129a1209153106296b3d2487547ba205/packages/material-ui/src/OutlinedInput/OutlinedInput.js#L101
assert.strictEqual(findOutermostIntrinsic(wrapper).hasClass(classes.root), true);
assert.strictEqual(findOutermostIntrinsic(wrapper).hasClass(className), true);
expect(findOutermostIntrinsic(wrapper).hasClass(classes.root)).to.equal(true);
expect(findOutermostIntrinsic(wrapper).hasClass(className)).to.equal(true);
});
}

Expand Down
4 changes: 2 additions & 2 deletions packages/material-ui/src/test-utils/testRef.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import * as React from 'react';
import { assert } from 'chai';
import { expect } from 'chai';

function assertDOMNode(node) {
// duck typing a DOM node
assert.ok(node.nodeName);
expect(typeof node.nodeName).to.equal('string');
}

/**
Expand Down
2 changes: 1 addition & 1 deletion packages/material-ui/src/test-utils/until.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ describe('until', () => {
).to.equal(true);
});

it('throws when assert.strictEqual called on an empty wrapper', () => {
it('throws when until called on an empty wrapper', () => {
expect(() => {
until.call(shallow(<Div />).find('Foo'), 'div');
}).to.throw(Error);
Expand Down
22 changes: 11 additions & 11 deletions test/utils/consoleErrorMock.test.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
import { assert } from 'chai';
import { expect } from 'chai';
import consoleErrorMock from './consoleErrorMock';

describe('consoleErrorMock()', () => {
describe('callCount()', () => {
it('should throw error when calling callCount() before spy()', () => {
assert.throws(() => {
expect(() => {
consoleErrorMock.callCount();
}, 'Requested call count before spy() was called');
}).to.throw('Requested call count before spy() was called');
});
});

describe('args', () => {
it('was removed but throws a descriptive error', () => {
assert.throws(
() => consoleErrorMock.args(),
expect(
() => consoleErrorMock.args()).to.throw(
'args() was removed in favor of messages(). Use messages() to match against the actual error message that will be displayed in the console.',
);
});
Expand All @@ -22,9 +22,9 @@ describe('consoleErrorMock()', () => {
describe('messages()', () => {
describe('when not spying', () => {
it('should throw error', () => {
assert.throws(() => {
expect(() => {
consoleErrorMock.messages();
}, 'Requested call count before spy() was called');
}).to.throw('Requested call count before spy() was called');
});
});

Expand All @@ -40,23 +40,23 @@ describe('consoleErrorMock()', () => {
it('returns the formatted output', () => {
console.error('expected %s but got %s', '1', 2);

assert.strictEqual(consoleErrorMock.messages()[0], 'expected 1 but got 2');
expect(consoleErrorMock.messages()[0]).to.equal('expected 1 but got 2');
});
});
});

describe('spy()', () => {
it('should place a spy in console.error', () => {
consoleErrorMock.spy();
assert.strictEqual(console.error.hasOwnProperty('isSinonProxy'), true);
expect(console.error.hasOwnProperty('isSinonProxy')).to.equal(true);
consoleErrorMock.reset();
assert.strictEqual(console.error.hasOwnProperty('isSinonProxy'), false);
expect(console.error.hasOwnProperty('isSinonProxy')).to.equal(false);
});

it('should keep the call count', () => {
consoleErrorMock.spy();
console.error();
assert.strictEqual(consoleErrorMock.callCount(), 1);
expect(consoleErrorMock.callCount()).to.equal(1);
consoleErrorMock.reset();
});
});
Expand Down

0 comments on commit a528ab4

Please sign in to comment.