Skip to content

Commit d8c58d7

Browse files
author
Michael Johnston
committed
Merge pull request Flipboard#38 from brentvatne/add-jest
Add Jest for unit testing
2 parents ddfecb4 + 3003652 commit d8c58d7

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

lib/__tests__/clamp-test.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
jest.dontMock('../clamp.js');
2+
3+
var clamp = require('../clamp');
4+
5+
describe('clamp', function() {
6+
it('returns the min if n is less than min', function() {
7+
expect(clamp(-1, 0, 1)).toBe(0);
8+
});
9+
10+
it('returns the max if n is greater than max', function() {
11+
expect(clamp(2, 0, 1)).toBe(1);
12+
});
13+
14+
it('returns n if n is between min and max', function() {
15+
expect(clamp(0.5, 0, 1)).toBe(0.5);
16+
});
17+
});

lib/clamp.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,3 @@
1010
module.exports = function (number, min, max) {
1111
return Math.min(Math.max(number, min), max);
1212
};
13-

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
"url": "https://github.com/Flipboard/react-canvas.git"
99
},
1010
"scripts": {
11-
"start": "./node_modules/.bin/gulp"
11+
"start": "./node_modules/.bin/gulp",
12+
"test": "./node_modules/.bin/jest"
1213
},
1314
"keywords": [
1415
"react",
@@ -26,6 +27,7 @@
2627
"gulp": "^3.8.10",
2728
"gulp-connect": "^2.2.0",
2829
"gulp-webpack": "^1.2.0",
30+
"jest-cli": "^0.2.2",
2931
"jsx-loader": "^0.12.2",
3032
"react": "^0.13.0-beta.1",
3133
"transform-loader": "^0.2.1",

0 commit comments

Comments
 (0)