Permalink
Browse files

Add tests

  • Loading branch information...
markdalgleish committed Jul 9, 2015
1 parent 0c35694 commit 4c08e107faa3dd16b089fa2fa452fb7b4feab9ed
Showing with 90 additions and 2 deletions.
  1. +1 −0 .gitignore
  2. +3 −0 .travis.yml
  3. +5 −2 package.json
  4. +81 −0 test/index.js
View
@@ -1,2 +1,3 @@
node_modules
dist
coverage
View
@@ -0,0 +1,3 @@
language: node_js
node_js:
- "0.10"
View
@@ -4,7 +4,7 @@
"description": "Utility for making React components easily themeable",
"main": "dist/index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"test": "babel-istanbul cover _mocha -- --compilers js:babel/register && babel-istanbul check-coverage --branches 100",
"build": "babel src -d dist",
"prepublish": "npm run build"
},
@@ -22,6 +22,9 @@
"object-assign": "^3.0.0"
},
"devDependencies": {
"babel": "^5.6.14"
"babel": "^5.6.14",
"babel-istanbul": "^0.2.10",
"chai": "^3.0.0",
"mocha": "^2.2.5"
}
}
View
@@ -0,0 +1,81 @@
import themeable from '../src';
import { expect } from 'chai';
describe('className', () => {
const classes = { foo: 'aaa', bar: 'bbb' };
const classTheme = themeable(classes);
it('should return a single class', () => {
expect(classTheme(1, 'foo'))
.to.deep.equal({
key: 1,
className: classes.foo
});
});
it('should return multiple classes', () => {
expect(classTheme(2, 'foo', 'bar'))
.to.deep.equal({
key: 2,
className: `${classes.foo} ${classes.bar}`
});
});
it('should ignore falsy values', () => {
expect(classTheme(1, null, 'foo', undefined, false))
.to.deep.equal({
key: 1,
className: classes.foo
});
});
});
describe('style', () => {
const styles = {
foo: {
color: 'red',
fontSize: '16px'
},
bar: {
color: 'blue',
fontWeight: 'bold'
}
};
const styleTheme = themeable(styles);
it('should return a single style', () => {
expect(styleTheme(1, 'foo'))
.to.deep.equal({
key: 1,
style: {
color: 'red',
fontSize: '16px'
}
});
});
it('should return multiple styles merged', () => {
expect(styleTheme(1, 'foo', 'bar'))
.to.deep.equal({
key: 1,
style: {
fontSize: '16px',
color: 'blue',
fontWeight: 'bold'
}
});
});
it('should ignore falsy values', () => {
expect(styleTheme(1, false, undefined, 'foo', null))
.to.deep.equal({
key: 1,
style: {
color: 'red',
fontSize: '16px'
}
});
});
});

0 comments on commit 4c08e10

Please sign in to comment.