Skip to content

Commit 44dce3e

Browse files
committed
Add some tests for the Button component
1 parent 8bf7168 commit 44dce3e

File tree

2 files changed

+44
-1
lines changed

2 files changed

+44
-1
lines changed

src/js/Button.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@ import React from 'react';
44
class Button extends React.PureComponent {
55
static propTypes = {
66
children: PropTypes.node.isRequired,
7-
title: PropTypes.string.isRequired,
7+
title: PropTypes.string,
8+
};
9+
10+
static defaultProps = {
11+
title: null,
812
};
913

1014
render() {

test/Button.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import React from 'react';
2+
import { shallow } from 'enzyme';
3+
import { assert } from 'chai';
4+
5+
import Button from '../src/js/Button';
6+
7+
describe('<Button />', () => {
8+
describe('title', () => {
9+
it('should copy `title` to `aria-label`', () => {
10+
const wrapper = shallow((
11+
<Button title="Collapse">
12+
Collapse
13+
</Button>
14+
));
15+
16+
assert.equal('Collapse', wrapper.find('button').prop('aria-label'));
17+
});
18+
19+
it('should set `type` to `button`', () => {
20+
const wrapper = shallow((
21+
<Button>
22+
Basic Button
23+
</Button>
24+
));
25+
26+
assert.equal('button', wrapper.find('button').prop('type'));
27+
});
28+
29+
it('should pass extra properties to the base button', () => {
30+
const wrapper = shallow((
31+
<Button className="btn">
32+
Basic Button
33+
</Button>
34+
));
35+
36+
assert.equal('btn', wrapper.find('button').prop('className'));
37+
});
38+
});
39+
});

0 commit comments

Comments
 (0)