Skip to content

Commit

Permalink
[MOD] 新增单元测试,覆盖率达到90%以上
Browse files Browse the repository at this point in the history
  • Loading branch information
qianxu.ljj committed Jan 4, 2018
1 parent a5ff00d commit bc64e4c
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 4 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,4 @@ spm_modules
dist
build
assets/**/*.css
coverage
2 changes: 1 addition & 1 deletion src/Collapse.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export default class Collapse extends Component {

static propTypes = {
prefixCls: PropTypes.string,
className: React.PropTypes.string,
className: PropTypes.string,
activeKey: PropTypes.oneOfType([
PropTypes.string,
PropTypes.arrayOf(PropTypes.string),
Expand Down
64 changes: 61 additions & 3 deletions tests/Collapse.spec.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,67 @@
import expect from 'expect.js';
import React from 'react';
import ReactDOM from 'react-dom';
import TestUtils, { Simulate } from 'react-addons-test-utils';
import Collapse from '../src';
import PropTypes from 'prop-types';
import Enzyme, { mount, shallow } from 'enzyme';
import Adapter from 'enzyme-adapter-react-15';
import Collapse, {Panel} from '../src';
import { setTimeout } from 'timers';

Enzyme.configure({ adapter: new Adapter() });

describe('Collapse', () => {
it('Collapse has correct propTypes', () => {
expect(Collapse.propTypes.prefixCls).to.be(PropTypes.string)
expect(Collapse.propTypes.className).to.be(PropTypes.string)
expect(Collapse.propTypes.activeKey).to.be.ok()
expect(Collapse.propTypes.defaultActiveKey).to.be.ok()
expect(Collapse.propTypes.onChange).to.be(PropTypes.func)
expect(Collapse.propTypes.accordion).to.be(PropTypes.bool)
expect(Collapse.propTypes.children).to.be(PropTypes.any)
})

it('Panel has correct propTypes', () => {
expect(Panel.propTypes.prefixCls).to.be(PropTypes.string)
expect(Panel.propTypes.header).to.be.ok()
expect(Panel.propTypes.isActive).to.be(PropTypes.bool)
expect(Panel.propTypes.onItemClick).to.be(PropTypes.func)
expect(Panel.propTypes.children).to.be(PropTypes.any)
})

let wrapper = mount(
<Collapse defaultActiveKey={['1']} accordion={false}>
<Panel header={'This is panel header 1'} key="1">
<p>1</p>
</Panel>
<Panel header={'This is panel header 2'} key="2">
<p>2</p>
</Panel>
<Panel header={'This is panel header 3'} key="3">
<p>3</p>
</Panel>
</Collapse>
)

it('has correct defaultActiveKey', () => {
expect(wrapper.state('activeKey')).to.eql(['1'])
})

it('has correct activeKey', () => {
wrapper.setProps({
activeKey: ['2']
})
expect(wrapper.state('activeKey')).to.eql(['2'])
})

it('has correct accordion', () => {
wrapper.setProps({
accordion: true
})
expect(wrapper.prop('accordion')).to.be(true)
})

});
it('has correct click', () => {
wrapper.find('.kuma-collapse-header').at(2).simulate('click')
expect(wrapper.state('activeKey')).to.be('3')
})
});

0 comments on commit bc64e4c

Please sign in to comment.