Skip to content

Commit

Permalink
chore(tests): Update tests to use better matchers
Browse files Browse the repository at this point in the history
  • Loading branch information
danez committed Feb 17, 2018
1 parent 647e8d2 commit 6ce7490
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions src/components/__tests__/Tabs-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ describe('<Tabs />', () => {
console.error = oldConsoleError; // eslint-disable-line no-console

const result = Tabs.propTypes.children(wrapper.props(), 'children', 'Tabs');
expect(result instanceof Error).toBe(true);
expect(result).toBeInstanceOf(Error);
});

test('should result with warning when tab outside of tablist', () => {
Expand All @@ -215,7 +215,7 @@ describe('<Tabs />', () => {
console.error = oldConsoleError; // eslint-disable-line no-console

const result = Tabs.propTypes.children(wrapper.props(), 'children', 'Tabs');
expect(result instanceof Error).toBe(true);
expect(result).toBeInstanceOf(Error);
});

test('should result with warning when multiple tablist components exist', () => {
Expand All @@ -236,15 +236,15 @@ describe('<Tabs />', () => {
console.error = oldConsoleError; // eslint-disable-line no-console

const result = Tabs.propTypes.children(wrapper.props(), 'children', 'Tabs');
expect(result instanceof Error).toBe(true);
expect(result).toBeInstanceOf(Error);
});

test('should result with warning when onSelect missing when selectedIndex set', () => {
const oldConsoleError = console.error; // eslint-disable-line no-console
const catchedErrors = [];
let catchedError;
// eslint-disable-next-line no-console
console.error = error => {
catchedErrors.push(error);
catchedError = error;
};
shallow(
<Tabs selectedIndex={1}>
Expand All @@ -258,15 +258,15 @@ describe('<Tabs />', () => {

const expectedMessage =
'The prop `onSelect` is marked as required in `Tabs`, but its value is `undefined` or `null`.';
expect(catchedErrors.some(msg => msg.indexOf(expectedMessage) > -1)).toBe(true);
expect(catchedError).toMatch(expectedMessage);
});

test('should result with warning when defaultIndex and selectedIndex set', () => {
const oldConsoleError = console.error; // eslint-disable-line no-console
const catchedErrors = [];
let catchedError;
// eslint-disable-next-line no-console
console.error = error => {
catchedErrors.push(error);
catchedError = error;
};
shallow(
<Tabs selectedIndex={1} defaultIndex={1}>
Expand All @@ -280,7 +280,7 @@ describe('<Tabs />', () => {

const expectedMessage =
'The prop `selectedIndex` cannot be used together with `defaultIndex` in `Tabs`.';
expect(catchedErrors.some(msg => msg.indexOf(expectedMessage) > -1)).toBe(true);
expect(catchedError).toMatch(expectedMessage);
});

test('should result with warning when tabs/panels are imbalanced and it should ignore non tab children', () => {
Expand All @@ -300,7 +300,7 @@ describe('<Tabs />', () => {
console.error = oldConsoleError; // eslint-disable-line no-console

const result = Tabs.propTypes.children(wrapper.props(), 'children', 'Tabs');
expect(result instanceof Error).toBe(true);
expect(result).toBeInstanceOf(Error);
});

test('should allow random order for elements', () => {
Expand Down

0 comments on commit 6ce7490

Please sign in to comment.