Skip to content
This repository has been archived by the owner on Jun 28, 2021. It is now read-only.

Commit

Permalink
refactor(Icon): Refactor Icon tests using enzyme
Browse files Browse the repository at this point in the history
  • Loading branch information
Tommy Leunen committed Jul 8, 2016
1 parent 41a13a9 commit e9ca4ba
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 31 deletions.
32 changes: 32 additions & 0 deletions src/Icon/__tests__/Icon-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/* eslint-env mocha */
import chai, { expect } from 'chai';
import chaiEnzyme from 'chai-enzyme';
import { shallow } from 'enzyme';
import React from 'react';
import Icon from '../';

chai.use(chaiEnzyme());

describe('Icon', () => {
it('should be a <i>', () => {
const wrapper = shallow(<Icon name="add" />);

expect(wrapper)
.to.have.tagName('i')
.to.have.text('add');
});

it('should have material-icons css class', () => {
const wrapper = shallow(<Icon name="add" />);

expect(wrapper).to.have.className('material-icons');
});

it('should allow custom css classes', () => {
const wrapper = shallow(<Icon name="mood" className="my-custom-class" />);

expect(wrapper)
.to.have.className('material-icons')
.to.have.className('my-custom-class');
});
});
10 changes: 6 additions & 4 deletions src/Icon.js → src/Icon/index.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
import React, { PropTypes } from 'react';
import classNames from 'classnames';

const propTypes = {
className: PropTypes.string,
name: PropTypes.string.isRequired
};

const Icon = (props) => {
const { className, name, ...otherProps } = props;
const classes = classNames('material-icons', className);

return <i className={classes} {...otherProps}>{name}</i>;
};

Icon.propTypes = {
className: PropTypes.string,
name: PropTypes.string.isRequired
};
Icon.propTypes = propTypes;

export default Icon;
27 changes: 0 additions & 27 deletions src/__tests__/Icon-test.js

This file was deleted.

0 comments on commit e9ca4ba

Please sign in to comment.