Skip to content

Commit

Permalink
Add Dashicon unit tests.
Browse files Browse the repository at this point in the history
Adds basic rendering dashicon unit tests.  Related to #641.  The
Dashicon should not render when an icon is not provided.
  • Loading branch information
BE-Webdesign committed May 29, 2017
1 parent 48ab106 commit 5f72463
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 1 deletion.
38 changes: 38 additions & 0 deletions components/dashicon/test/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/**
* External dependencies
*/
import { expect } from 'chai';
import { shallow } from 'enzyme';

/**
* Internal dependencies
*/
import Dashicon from '../';

describe( 'Dashicon', () => {
describe( 'basic rendering', () => {
it( 'without properties', () => {
const dashicon = shallow( <Dashicon /> );
// Unrendered element.
expect( dashicon.type() ).to.be.null();
} );

it( 'with icon property', () => {
const dashicon = shallow( <Dashicon icon="wordpress" /> );
// OH NO CAPITAL P DANGIT!
expect( dashicon.find( 'title' ).text() ).to.equal( 'Wordpress' );
expect( dashicon.hasClass( 'dashicon' ) ).to.be.true();
expect( dashicon.hasClass( 'dashicons-wordpress' ) ).to.be.true();
expect( dashicon.type() ).to.equal( 'svg' );
expect( dashicon.prop( 'xmlns' ) ).to.equal( 'http://www.w3.org/2000/svg' );
expect( dashicon.prop( 'width' ) ).to.equal( '20' );
expect( dashicon.prop( 'height' ) ).to.equal( '20' );
expect( dashicon.prop( 'viewBox' ) ).to.equal( '0 0 20 20' );
} );

it( 'with additional class name', () => {
const dashicon = shallow( <Dashicon icon="wordpress" className="capital-p-dangit" /> );
expect( dashicon.hasClass( 'capital-p-dangit' ) ).to.be.true();
} );
} );
} );
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"cross-env": "^3.2.4",
"deep-freeze": "0.0.1",
"dirty-chai": "^1.2.2",
"enzyme": "^2.8.2",
"eslint": "^3.17.1",
"eslint-config-wordpress": "^1.1.0",
"eslint-plugin-jsx-a11y": "^4.0.0",
Expand All @@ -50,6 +51,7 @@
"pegjs-loader": "^0.5.1",
"postcss-loader": "^1.3.3",
"raw-loader": "^0.5.1",
"react-test-renderer": "^15.5.4",
"sass-loader": "^6.0.3",
"sinon": "^2.1.0",
"sinon-chai": "^2.9.0",
Expand Down
2 changes: 1 addition & 1 deletion webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ switch ( process.env.NODE_ENV ) {
...config.module.rules,
];
const testFiles = glob.sync(
'./{' + Object.keys( config.entry ).sort() + '}/**/test/*.js'
'./{' + Object.keys( config.entry ).concat( 'components' ).sort() + '}/**/test/*.js'
);
config.entry = [
'./date/index.js',
Expand Down

0 comments on commit 5f72463

Please sign in to comment.