Skip to content

Commit 2935eca

Browse files
committed
Add Mocha and Chai.
1 parent 9e5f254 commit 2935eca

File tree

3 files changed

+59
-5
lines changed

3 files changed

+59
-5
lines changed

.eslintrc

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
"env": {
44
"browser": true,
55
"node": true,
6-
"es6": true
6+
"es6": true,
7+
"mocha": true
78
},
89
"ecmaFeatures": {
910
"modules": true,
@@ -116,7 +117,7 @@
116117
}],
117118
"lines-around-comment": 0, // Do not require new line before comments
118119
"linebreak-style": [2, "unix"], // Unix linebreaks
119-
"max-nested-callbacks": [1, 2], // No more than 2 levels of nested callbacks
120+
"max-nested-callbacks": [1, 3], // No more than 3 levels of nested callbacks
120121
"new-cap": 0, // Do not require capital letter for constructors
121122
"new-parens": 2, // Disallow the omission of parentheses when invoking a constructor with no arguments
122123
"no-lonely-if": 1, // Disallow if as the only statement in an else block
@@ -133,7 +134,6 @@
133134
"no-useless-concat": 1, // Disallow unncessary concatenation of strings
134135
"operator-assignment": [1, "always"], // Require assignment operator shorthand where possible
135136
"operator-linebreak": [1, "after"], // Operators should be placed before line breaks
136-
"padded-blocks": [1, "never"], // Disallow padding within blocks
137137
"quote-props": 0, // Do not require quotes around object literal property names
138138
"quotes": [1, "single", "avoid-escape"], // Single quotes
139139
"semi-spacing": [1, { // No space before semicolon, space after semicolon
@@ -203,6 +203,8 @@
203203
// }],
204204
"react/wrap-multilines": 1
205205
},
206-
"globals": {
206+
"globals": {
207+
"describe": false,
208+
"it": false
207209
}
208210
}

package.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,15 +63,19 @@
6363
},
6464
"devDependencies": {
6565
"babel-eslint": "4.1.3",
66+
"chai": "~3.4.1",
6667
"eslint": "1.7.3",
6768
"eslint-plugin-react": "3.6.3",
6869
"gulp": "3.9.0",
6970
"gulp-gh-pages": "0.5.4",
71+
"mocha": "~2.3.3",
7072
"react": "0.14.0",
7173
"react-dom": "0.14.0"
7274
},
7375
"scripts": {
74-
"test": "npm run lint && npm run build",
76+
"test": "npm run lint && npm run mocha && npm run build",
77+
"mocha": "mocha --compilers js:babel-core/register test",
78+
"mocha:watch": "mocha --watch --reporter min --compilers js:babel/register test",
7579
"start": "./bin/styleguidist server --config example/styleguide.config.js",
7680
"lint": "eslint src --ext .js",
7781
"build": "./bin/styleguidist build --config example/styleguide.config.js",

test/utils.utils.spec.js

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import { expect } from 'chai';
2+
import _ from 'lodash';
3+
4+
import * as utils from '../src/utils/utils';
5+
6+
describe('utils', () => {
7+
8+
describe('setComponentsNames', () => {
9+
it('should set name property to each component', () => {
10+
let result = utils.setComponentsNames([
11+
{
12+
module: {displayName: 'Foo'}
13+
},
14+
{
15+
module: {name: 'Bar'}
16+
}
17+
]);
18+
expect(_.pluck(result, 'name')).to.eql(['Foo', 'Bar']);
19+
});
20+
});
21+
22+
describe('globalizeComponents', () => {
23+
let sourceGlobalLength;
24+
beforeEach(() => {
25+
sourceGlobalLength = Object.keys(global).length;
26+
});
27+
afterEach(() => {
28+
delete global.Foo;
29+
delete global.Bar;
30+
});
31+
it('should set each component’s module as a global variable', () => {
32+
utils.globalizeComponents([
33+
{
34+
name: 'Foo',
35+
module: 13
36+
},
37+
{
38+
name: 'Bar',
39+
module: 27
40+
}
41+
]);
42+
expect(Object.keys(global).length).to.eql(sourceGlobalLength + 2);
43+
expect(global.Foo).to.eql(13);
44+
expect(global.Bar).to.eql(27);
45+
});
46+
});
47+
48+
});

0 commit comments

Comments
 (0)