UNPKG

tin-react-components

Version:
32 lines (30 loc) 1.2 kB
import React from 'react' import { mount } from 'enzyme' import { expect } from 'chai' import sinon from 'sinon' import Button from '../index' describe('<Button />', () => { const onClick = sinon.spy() const buttonTexts = ['btn1', 'Button', 'LONG BUTTON TEXT'] const buttonTypes = ['primary', 'secondary'] it('should show a button', () => { const wrapper = mount(<Button onClick={onClick} />) expect(wrapper.find('button')).to.have.length(1) }) buttonTexts.forEach((btnText, i) => { it(`should show a button with ${btnText} as the text, given the property 'text' === ${btnText}`, () => { const wrapper = mount(<Button onClick={onClick} text={btnText} />) expect(wrapper.find('button').text()).to.equal(btnText) expect(wrapper.props().text).to.equal(btnText) wrapper.find('button').simulate('click') expect(onClick).to.have.property('callCount', i + 1) }) }) buttonTypes.forEach((type, i) => { it(`should show a button with ${type} as a class`, () => { const wrapper = mount(<Button onClick={onClick} type={type} />) const button = wrapper.find('button') expect(button.hasClass(type)).to.equal(true) }) }) })