Navigation Menu

Skip to content

Commit

Permalink
Merge pull request #133 from webdeveloperpr/feat/fix-empty-arrays
Browse files Browse the repository at this point in the history
Fix issue with empty arrays being pushed
  • Loading branch information
dcousens committed May 17, 2017
2 parents 0469d5f + fc336c5 commit 616cacd
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
7 changes: 5 additions & 2 deletions index.js
Expand Up @@ -21,8 +21,11 @@

if (argType === 'string' || argType === 'number') {
classes.push(arg);
} else if (Array.isArray(arg)) {
classes.push(classNames.apply(null, arg));
} else if (Array.isArray(arg) && arg.length) {
var inner = classNames.apply(null, arg);
if (inner) {
classes.push(inner);
}
} else if (argType === 'object') {
for (var key in arg) {
if (hasOwn.call(arg, key) && arg[key]) {
Expand Down
8 changes: 8 additions & 0 deletions tests/index.js
Expand Up @@ -59,4 +59,12 @@ describe('classNames', function () {
it('handles deep array recursion', function () {
assert.equal(classNames(['a', ['b', ['c', {d: true}]]]), 'a b c d');
});

it('handles arrays that are empty', function () {
assert.equal(classNames('a', []), 'a');
});

it('handles nested arrays that have empty nested arrays', function () {
assert.equal(classNames('a', [[]]), 'a');
});
});

0 comments on commit 616cacd

Please sign in to comment.