Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
markdalgleish committed Jul 9, 2015
1 parent 0c35694 commit 4c08e10
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
node_modules
dist
coverage
3 changes: 3 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
language: node_js
node_js:
- "0.10"
7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand All @@ -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"
}
}
81 changes: 81 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
@@ -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.