Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(project): add setup for test failure with unexpected console #5184

Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/components/tests/styles-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const files = glob.sync('**/*.scss', {
const render = promisify(sass.render);

describe('styles', () => {
jest.setTimeout(8000);
jest.setTimeout(10000);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW I had to change this to 12000 to not get an error 🤷‍♂

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ooof, same. Let me bump up to 20000 just in case

joshblack marked this conversation as resolved.
Show resolved Hide resolved
it.each(files)('%s should compile', async relativeFilePath => {
const filepath = path.join(cwd, relativeFilePath);
try {
Expand Down
9 changes: 8 additions & 1 deletion packages/react/src/components/Checkbox/Checkbox-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,14 @@ describe('refs', () => {
this.myRef = React.createRef();
}
render() {
return <Checkbox indeterminate ref={this.myRef} />;
return (
<Checkbox
id="test-id"
labelText="test"
indeterminate
ref={this.myRef}
/>
);
}
}
const wrapper = mount(<MyComponent />);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ describe('DataTable', () => {
Action 3
</TableToolbarAction>
</TableToolbarMenu>
<Button onClick={jest.fn()} small kind="primary">
<Button onClick={jest.fn()} size="small" kind="primary">
Add new
</Button>
</TableToolbarContent>
Expand Down Expand Up @@ -400,7 +400,7 @@ describe('DataTable', () => {
Action 3
</TableToolbarAction>
</TableToolbarMenu>
<Button onClick={jest.fn()} small kind="primary">
<Button onClick={jest.fn()} size="small" kind="primary">
Add new
</Button>
</TableToolbarContent>
Expand Down Expand Up @@ -689,6 +689,7 @@ describe('DataTable', () => {
rows,
headers,
getHeaderProps,
getExpandHeaderProps,
getSelectionProps,
getBatchActionProps,
getRowProps,
Expand All @@ -704,7 +705,7 @@ describe('DataTable', () => {
<Table>
<TableHead>
<TableRow>
<TableExpandHeader />
<TableExpandHeader {...getExpandHeaderProps()} />
<TableSelectAll {...getSelectionProps()} />
{headers.map(header => (
<TableHeader {...getHeaderProps({ header })}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ import { TableBatchAction } from '../';

describe('DataTable.TableBatchAction', () => {
it('should render', () => {
const wrapper = mount(<TableBatchAction className="custom-class" />);
const wrapper = mount(
<TableBatchAction className="custom-class" iconDescription="test" />
);
expect(wrapper).toMatchSnapshot();
});

Expand All @@ -21,7 +23,7 @@ describe('DataTable.TableBatchAction', () => {
<circle cx="16" cy="16" r="8" />
</svg>
));
mount(<TableBatchAction renderIcon={renderIcon} />);
mount(<TableBatchAction iconDescription="test" renderIcon={renderIcon} />);
expect(renderIcon).toHaveBeenCalled();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,12 @@ describe('DataTable.TableExpandHeader', () => {
<Table>
<TableHead>
<TableRow>
<TableExpandHeader className="custom-class" />
<TableExpandHeader
ariaLabel="test-label"
isExpanded={false}
onExpand={jest.fn()}
className="custom-class"
/>
</TableRow>
</TableHead>
</Table>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ describe('DataTable.TableExpandRow', () => {
<Table>
<TableBody>
<TableExpandRow {...mockProps} />
<TableExpandedRow />
<TableExpandedRow colSpan={1} />
</TableBody>
</Table>
);
Expand All @@ -38,7 +38,7 @@ describe('DataTable.TableExpandRow', () => {
<Table>
<TableBody>
<TableExpandRow {...mockProps} />
<TableExpandedRow />
<TableExpandedRow colSpan={1} />
</TableBody>
</Table>
);
Expand All @@ -63,7 +63,7 @@ describe('DataTable.TableExpandRow', () => {
<Table>
<TableBody>
<TableExpandRow {...mockProps} />
<TableExpandedRow />
<TableExpandedRow colSpan={1} />
</TableBody>
</Table>
);
Expand All @@ -74,7 +74,7 @@ describe('DataTable.TableExpandRow', () => {
<Table>
<TableBody>
<TableExpandRow {...mockProps} isExpanded />
<TableExpandedRow />
<TableExpandedRow colSpan={1} />
</TableBody>
</Table>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ describe('DataTable.TableToolbarMenu', () => {
<TableToolbarMenu
className="custom-class"
renderIcon={Download16}
iconDescription="Add"
/>
iconDescription="Add">
<span>test</span>
</TableToolbarMenu>
);
expect(wrapper).toMatchSnapshot();
});
Expand All @@ -26,7 +27,9 @@ describe('DataTable.TableToolbarMenu', () => {
describe('Custom icon in DataTable.TableToolbarMenu', () => {
it('should render', () => {
const iconAction = mount(
<TableToolbarMenu renderIcon={Download16} iconDescription="Download" />
<TableToolbarMenu renderIcon={Download16} iconDescription="Download">
<span>test</span>
</TableToolbarMenu>
);
const originalIcon = mount(<Download16 />).find('svg');
const icon = iconAction.find('svg');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1851,7 +1851,7 @@ exports[`DataTable should render 1`] = `
disabled={false}
kind="primary"
onClick={[MockFunction]}
small={true}
size="small"
tabIndex={0}
type="button"
>
Expand Down Expand Up @@ -2456,7 +2456,7 @@ exports[`DataTable should render 1`] = `
disabled={false}
kind="primary"
onClick={[MockFunction]}
small={true}
size="small"
tabIndex={0}
type="button"
>
Expand Down Expand Up @@ -2830,7 +2830,7 @@ exports[`DataTable sticky header should render 1`] = `
disabled={false}
kind="primary"
onClick={[MockFunction]}
small={true}
size="small"
tabIndex={0}
type="button"
>
Expand Down Expand Up @@ -3438,7 +3438,7 @@ exports[`DataTable sticky header should render 1`] = `
disabled={false}
kind="primary"
onClick={[MockFunction]}
small={true}
size="small"
tabIndex={0}
type="button"
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
exports[`DataTable.TableBatchAction should render 1`] = `
<TableBatchAction
className="custom-class"
iconDescription="test"
renderIcon={
Object {
"$$typeof": Symbol(react.forward_ref),
Expand All @@ -13,6 +14,7 @@ exports[`DataTable.TableBatchAction should render 1`] = `
<ForwardRef(Button)
className="custom-class"
disabled={false}
iconDescription="test"
kind="primary"
renderIcon={
Object {
Expand All @@ -31,10 +33,12 @@ exports[`DataTable.TableBatchAction should render 1`] = `
>
<ForwardRef(AddFilled16)
aria-hidden="true"
aria-label="test"
className="bx--btn__icon"
>
<Icon
aria-hidden="true"
aria-label="test"
className="bx--btn__icon"
height={16}
preserveAspectRatio="xMidYMid meet"
Expand All @@ -43,11 +47,13 @@ exports[`DataTable.TableBatchAction should render 1`] = `
xmlns="http://www.w3.org/2000/svg"
>
<svg
aria-hidden={true}
aria-hidden="true"
aria-label="test"
className="bx--btn__icon"
focusable="false"
height={16}
preserveAspectRatio="xMidYMid meet"
role="img"
style={
Object {
"willChange": "transform",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ exports[`DataTable.TableExpandHeader should render 1`] = `
<TableRow>
<tr>
<TableExpandHeader
ariaLabel="test-label"
className="custom-class"
isExpanded={false}
onExpand={[MockFunction]}
>
<th
className="bx--table-expand custom-class"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,15 +74,21 @@ exports[`DataTable.TableExpandRow should render 1`] = `
</TableCell>
</tr>
</TableExpandRow>
<TableExpandedRow>
<TableExpandedRow
colSpan={1}
>
<tr
className="bx--expandable-row"
data-child-row={true}
onMouseEnter={[Function]}
onMouseLeave={[Function]}
>
<TableCell>
<td>
<TableCell
colSpan={1}
>
<td
colSpan={1}
>
<div
className="bx--child-row-inner-container"
/>
Expand Down
19 changes: 16 additions & 3 deletions packages/react/src/components/DatePicker/DatePicker-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -281,14 +281,19 @@ describe('DatePicker', () => {
});

describe('Date picker can be used with enzyme shallow', () => {
let spy;
beforeEach(done => {
const spy = {};
spy = {};
spy.console = jest.spyOn(console, 'error').mockImplementation(e => {
done(e);
});
done();
});

afterEach(() => {
spy.console.mockRestore();
});

it('date picker should not throw exception when mounted or unmounted', () => {
const wrapper = shallow(
<DatePicker
Expand Down Expand Up @@ -318,7 +323,15 @@ describe('DatePicker', () => {
});

describe('Date picker with minDate and maxDate', () => {
console.error = jest.fn(); // eslint-disable-line no-console
let mockConsoleError;

beforeEach(() => {
mockConsoleError = jest.spyOn(console, 'error');
});

afterEach(() => {
mockConsoleError.mockRestore();
});

const wrapper = mount(
<DatePicker
Expand Down Expand Up @@ -351,7 +364,7 @@ describe('DatePicker', () => {
});

it('should not have "console.error" being created', () => {
expect(console.error).not.toBeCalled(); // eslint-disable-line no-console
expect(mockConsoleError).not.toBeCalled();
});
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,8 @@ describe('NumberInput', () => {
);
});

it('should avoid capping when non-number prop is given to value prop', () => {
// NumberInput propTypes do not allow a string to be passed
it.skip('should avoid capping when non-number prop is given to value prop', () => {
// Enzyme doesn't seem to allow setState() in a forwardRef-wrapped class component
wrapper
.find('NumberInput')
Expand Down
19 changes: 10 additions & 9 deletions packages/react/src/components/OverflowMenu/OverflowMenu-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import React from 'react';
import OverflowMenu from '../OverflowMenu';
import OverflowMenuItem from '../OverflowMenuItem';
import { OverflowMenuVertical16 } from '@carbon/icons-react';
import { mount } from 'enzyme';
import { settings } from 'carbon-components';
Expand All @@ -17,8 +18,8 @@ describe('OverflowMenu', () => {
describe('Renders as expected', () => {
const rootWrapper = mount(
<OverflowMenu className="extra-class">
<div className="test-child" />
<div className="test-child" />
<OverflowMenuItem className="test-child">one</OverflowMenuItem>
<OverflowMenuItem className="test-child">two</OverflowMenuItem>
</OverflowMenu>
);
const menu = rootWrapper.find(`button.${prefix}--overflow-menu`);
Expand Down Expand Up @@ -122,8 +123,8 @@ describe('OverflowMenu', () => {
it('should render a ul with the appropriate class', () => {
const rootWrapper = mount(
<OverflowMenu menuOptionsClass="extra-menu-class">
<div className="test-child" />
<div className="test-child" />
<OverflowMenuItem className="test-child">one</OverflowMenuItem>
<OverflowMenuItem className="test-child">two</OverflowMenuItem>
</OverflowMenu>
);
// Enzyme doesn't seem to allow setState() in a forwardRef-wrapped class component
Expand All @@ -141,8 +142,8 @@ describe('OverflowMenu', () => {
it('should render children as expected', () => {
const rootWrapper = mount(
<OverflowMenu>
<div className="test-child" />
<div className="test-child" />
<OverflowMenuItem className="test-child">one</OverflowMenuItem>
<OverflowMenuItem className="test-child">two</OverflowMenuItem>
</OverflowMenu>
);
// Enzyme doesn't seem to allow setState() in a forwardRef-wrapped class component
Expand All @@ -151,7 +152,7 @@ describe('OverflowMenu', () => {
.instance()
.setState({ open: true });
rootWrapper.update();
expect(rootWrapper.find('.test-child').length).toEqual(2);
expect(rootWrapper.find('button.test-child').length).toEqual(2);
});

it('should set expected class when state is open', () => {
Expand Down Expand Up @@ -267,8 +268,8 @@ describe('OverflowMenu', () => {
<OverflowMenu
className="extra-class"
renderIcon={() => <div className="other">Other</div>}>
<div className="test-child" />
<div className="test-child" />
<OverflowMenuItem className="test-child">one</OverflowMenuItem>
<OverflowMenuItem className="test-child">two</OverflowMenuItem>
</OverflowMenu>
);
// renderIcon should be the only component where `${prefix}--overflow-menu__icon` class is applied,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ import { shallow } from 'enzyme';
import { settings } from 'carbon-components';

const { prefix } = settings;
const shallowRender = props => shallow(<OverflowMenuItem {...props} />);
const shallowRender = props =>
shallow(<OverflowMenuItem closeMenu={jest.fn()} {...props} />);

describe('OverflowMenuItem', () => {
describe('Renders as expected', () => {
Expand Down
Loading