Skip to content

Commit daf85d9

Browse files
committed
Fix tests
1 parent 772711a commit daf85d9

File tree

8 files changed

+4771
-6
lines changed

8 files changed

+4771
-6
lines changed

.gitignore

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
.idea
2-
*.iml
31
build/
42
node_modules/
53
npm-debug.log
64
lib/
7-
yarn.lock

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
"react-addons-test-utils": "^15.0.0",
6363
"react-dom": "^15.0.0",
6464
"react-modal": "^1.3.0",
65+
"react-test-renderer": "^15.5.4",
6566
"rimraf": "^2.5.2",
6667
"webpack": "^1.13.1",
6768
"webpack-dev-server": "^1.14.1"

src/components/Tab.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ export default class Tab extends Component {
5555
id,
5656
panelId,
5757
selected,
58+
tabRef,
5859
...attributes } = this.props;
5960

6061
return (
@@ -68,7 +69,7 @@ export default class Tab extends Component {
6869
[disabledTabClassName]: disabled,
6970
}
7071
)}
71-
ref={(node) => { this.node = node; this.props.tabRef(node); }}
72+
ref={(node) => { this.node = node; if (tabRef) tabRef(node); }}
7273
role="tab"
7374
id={id}
7475
aria-selected={selected ? 'true' : 'false'}

src/components/__tests__/Tab-test.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ import { shallow } from 'enzyme';
44
import Tab from '../Tab';
55

66
describe('<Tab />', () => {
7+
beforeAll(() => {
8+
console.error = (error) => {
9+
throw new Error(error);
10+
};
11+
});
12+
713
it('should have sane defaults', () => {
814
const wrapper = shallow(<Tab />);
915

src/components/__tests__/TabList-test.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,20 @@ import React from 'react';
33
import { shallow, mount } from 'enzyme';
44
import Tab from '../Tab';
55
import TabList from '../TabList';
6+
import TabPanel from '../TabPanel';
67
import Tabs from '../Tabs';
78

89
function hasClassAt(wrapper, index, className) {
910
return wrapper.childAt(index).find('li').hasClass(className);
1011
}
1112

1213
describe('<TabList />', () => {
14+
beforeAll(() => {
15+
console.error = (error) => {
16+
throw new Error(error);
17+
};
18+
});
19+
1320
it('should have sane defaults', () => {
1421
const wrapper = shallow(<TabList />);
1522

@@ -44,6 +51,8 @@ describe('<TabList />', () => {
4451
<Tab>Foo</Tab>
4552
<Tab disabled>Bar</Tab>
4653
</TabList>
54+
<TabPanel>Foo</TabPanel>
55+
<TabPanel>Bar</TabPanel>
4756
</Tabs>
4857
);
4958

@@ -59,6 +68,8 @@ describe('<TabList />', () => {
5968
<Tab>Foo</Tab>
6069
<Tab disabled>Bar</Tab>
6170
</TabList>
71+
<TabPanel>Foo</TabPanel>
72+
<TabPanel>Bar</TabPanel>
6273
</Tabs>
6374
);
6475

src/components/__tests__/TabPanel-test.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,13 @@ import React from 'react';
33
import { shallow } from 'enzyme';
44
import TabPanel from '../TabPanel';
55

6-
describe('Tab', () => {
6+
describe('<TabPanel />', () => {
7+
beforeAll(() => {
8+
console.error = (error) => {
9+
throw new Error(error);
10+
};
11+
});
12+
713
it('should have sane defaults', () => {
814
const wrapper = shallow(<TabPanel>Hola</TabPanel>);
915

src/components/__tests__/Tabs-test.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,13 @@ function assertTabSelected(wrapper, index) {
3838
expect(panel.prop('selected')).toBe(true);
3939
}
4040

41-
describe('react-tabs', () => {
41+
describe('<Tabs />', () => {
42+
beforeAll(() => {
43+
console.error = (error) => {
44+
throw new Error(error);
45+
};
46+
});
47+
4248
describe('props', () => {
4349
it('should default to selectedIndex being 0', () => {
4450
const wrapper = shallow(createTabs());
@@ -211,20 +217,25 @@ describe('react-tabs', () => {
211217

212218
describe('validation', () => {
213219
it('should result with warning when tabs/panels are imbalanced', () => {
220+
const oldConsoleError = console.error; // eslint-disable-line no-console
221+
console.error = () => {}; // eslint-disable-line no-console
214222
const wrapper = shallow(
215223
<Tabs>
216224
<TabList>
217225
<Tab>Foo</Tab>
218226
</TabList>
219227
</Tabs>
220228
);
229+
console.error = oldConsoleError; // eslint-disable-line no-console
221230

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

226235
it(`should result with warning when tabs/panels are imbalanced and
227236
it should ignore non tab children`, () => {
237+
const oldConsoleError = console.error; // eslint-disable-line no-console
238+
console.error = () => {}; // eslint-disable-line no-console
228239
const wrapper = shallow(
229240
<Tabs>
230241
<TabList>
@@ -236,6 +247,7 @@ describe('react-tabs', () => {
236247
<TabPanel>Hello Bar</TabPanel>
237248
</Tabs>
238249
);
250+
console.error = oldConsoleError; // eslint-disable-line no-console
239251

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

0 commit comments

Comments
 (0)