1 |
|
2 |
|
3 | var assert = require('assert');
|
4 | var classNames = require('../');
|
5 |
|
6 | describe('classNames', function () {
|
7 | it('keeps object keys with truthy values', function () {
|
8 | assert.equal(classNames({
|
9 | a: true,
|
10 | b: false,
|
11 | c: 0,
|
12 | d: null,
|
13 | e: undefined,
|
14 | f: 1
|
15 | }), 'a f');
|
16 | });
|
17 |
|
18 | it('joins arrays of class names and ignore falsy values', function () {
|
19 | assert.equal(classNames('a', 0, null, undefined, true, 1, 'b'), 'a 1 b');
|
20 | });
|
21 |
|
22 | it('supports heterogenous arguments', function () {
|
23 | assert.equal(classNames({a: true}, 'b', 0), 'a b');
|
24 | });
|
25 |
|
26 | it('should be trimmed', function () {
|
27 | assert.equal(classNames('', 'b', {}, ''), 'b');
|
28 | });
|
29 |
|
30 | it('returns an empty string for an empty configuration', function () {
|
31 | assert.equal(classNames({}), '');
|
32 | });
|
33 |
|
34 | it('supports an array of class names', function () {
|
35 | assert.equal(classNames(['a', 'b']), 'a b');
|
36 | });
|
37 |
|
38 | it('joins array arguments with string arguments', function () {
|
39 | assert.equal(classNames(['a', 'b'], 'c'), 'a b c');
|
40 | assert.equal(classNames('c', ['a', 'b']), 'c a b');
|
41 | });
|
42 |
|
43 | it('handles multiple array arguments', function () {
|
44 | assert.equal(classNames(['a', 'b'], ['c', 'd']), 'a b c d');
|
45 | });
|
46 |
|
47 | it('handles arrays that include falsy and true values', function () {
|
48 | assert.equal(classNames(['a', 0, null, undefined, false, true, 'b']), 'a b');
|
49 | });
|
50 |
|
51 | it('handles arrays that include arrays', function () {
|
52 | assert.equal(classNames(['a', ['b', 'c']]), 'a b c');
|
53 | });
|
54 |
|
55 | it('handles arrays that include objects', function () {
|
56 | assert.equal(classNames(['a', {b: true, c: false}]), 'a b');
|
57 | });
|
58 |
|
59 | it('handles deep array recursion', function () {
|
60 | assert.equal(classNames(['a', ['b', ['c', {d: true}]]]), 'a b c d');
|
61 | });
|
62 | });
|