Skip to content

Commit

Permalink
add unit test and improve code coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
paseo committed Jan 12, 2018
1 parent f681a99 commit bfb2ec3
Showing 1 changed file with 46 additions and 1 deletion.
47 changes: 46 additions & 1 deletion tests/Carousel.spec.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,54 @@
import expect from 'expect.js';
import React from 'react';
import ReactDOM from 'react-dom';
import TestUtils, { Simulate } from 'react-addons-test-utils';
import Enzyme, { mount } from 'enzyme';
import Adapter from 'enzyme-adapter-react-15'
import TestUtils, { Simulate } from 'react-dom/test-utils';
import Carousel from '../src';

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

describe('Carousel', () => {
it('className prop works', () => {
const node = mount(<Carousel className="test-classname"/>)
expect(node.props().className).to.equal('test-classname')
})

it('prefixCls prop works', () => {
const node = mount(<Carousel prefixCls="test-prefix"/>)
expect(node.find('.test-prefix')).to.have.length(1)
})

it('centerDots prop works', () => {
const node1 = mount(<Carousel prefixCls="test-prefix" />)
expect(node1.find('.test-prefix-dots-centered')).to.have.length(1)

const node2 = mount(<Carousel prefixCls="test-prefix" centerDots={false}>
</Carousel>)
expect(node2.find('.test-prefix-dots-centered')).to.have.length(0)
})

it('largeArrowsAndDots prop works', () => {
const node1 = mount(<Carousel prefixCls="test-prefix"/>)
expect(node1.find('.test-prefix-large-mode')).to.have.length(0)

const node2 = mount(<Carousel prefixCls="test-prefix" largeArrowsAndDots/>)
expect(node2.find('.test-prefix-large-mode')).to.have.length(1)
})

it('arrows === always works', () => {
const node1 = mount(<Carousel prefixCls="test-prefix" arrows="test"/>)
expect(node1.find('.test-prefix-always-show-arrows')).to.have.length(0)

const node2 = mount(<Carousel prefixCls="test-prefix" arrows="always"/>)
expect(node1.find('.test-prefix-always-show-arrows')).to.have.length(0)
})

it('coverage improve', () => {
// code coverage for children.length > 0
mount(<Carousel>
<div>a</div>
</Carousel>)
})

});

0 comments on commit bfb2ec3

Please sign in to comment.