Skip to content

Commit 34d8692

Browse files
levithomasonkyleturco
authored andcommitted
update tests for private components and sub-components
1 parent 8e3b658 commit 34d8692

1 file changed

Lines changed: 27 additions & 11 deletions

File tree

test/specs/index-test.js

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,41 @@ import _ from 'lodash';
22
import path from 'path';
33
import stardust from 'stardust';
44

5-
const componentPaths = require.context(
5+
const componentCtx = require.context(
66
'src/',
77
true,
88
/(addons|collections|elements|modules|views).*\.js$/
99
);
1010

11-
const componentNames = _.map(componentPaths.keys(), key => {
11+
const componentNames = _.map(componentCtx.keys(), key => {
1212
return path.basename(key).replace('.js', '');
1313
});
1414

15-
describe('index.js', () => {
16-
it('has a property for every component', () => {
17-
_.each(componentNames, component => {
18-
expect(stardust).to.have.any.keys(component);
19-
expect(stardust[component]).to.be.a('function');
20-
});
21-
});
15+
describe('stardust (index.js)', () => {
16+
_.each(componentNames, name => {
17+
const isPrivate = _.startsWith(name, '_');
18+
const isStardustProp = _.has(stardust, name); // => stardust.H1
19+
const isSubComponent = _.some(stardust, name); // => stardust.Header.H1
20+
// console.log(`${name} isStardustProp=${isStardustProp} isSubComponent=${isSubComponent}`);
21+
22+
if (isPrivate) {
23+
it(`does not expose private component "${name}"`, () => {
24+
expect(!isStardustProp).to.equal(true,
25+
`"${name}" is private (starts with "_"), it cannot be a key on the stardust object`
26+
);
27+
28+
expect(!isSubComponent).to.equal(true,
29+
`"${name}" is private (starts with "_"), it cannot be a static prop of another component (sub-component)`
30+
);
31+
});
32+
}
2233

23-
it('only has properties which correspond to components', () => {
24-
_.each(stardust, component => expect(component in componentNames));
34+
if (!isPrivate) {
35+
it(`exposes public component "${name}"`, () => {
36+
expect(!isPrivate && !isStardustProp && !isSubComponent).to.equal(false,
37+
`"${name}" must be: a key on stardust || key on another component (sub-component) || private (start with "_")`
38+
);
39+
});
40+
}
2541
});
2642
});

0 commit comments

Comments
 (0)