UNPKG

3.96 kBJavaScriptView Raw
1/* global describe, it */
2
3var assert = require('assert');
4var classNames = require('../bind');
5
6var cssModulesMock = {
7 a: "#a",
8 b: "#b",
9 c: "#c",
10 d: "#d",
11 e: "#e",
12 f: "#f"
13};
14
15var classNamesBound = classNames.bind(cssModulesMock);
16
17describe('bind', function () {
18 describe('classNames', function () {
19 it('keeps object keys with truthy values', function () {
20 assert.equal(classNames({
21 a: true,
22 b: false,
23 c: 0,
24 d: null,
25 e: undefined,
26 f: 1
27 }), 'a f');
28 });
29
30 it('joins arrays of class names and ignore falsy values', function () {
31 assert.equal(classNames('a', 0, null, undefined, true, 1, 'b'), 'a 1 b');
32 });
33
34 it('supports heterogenous arguments', function () {
35 assert.equal(classNames({a: true}, 'b', 0), 'a b');
36 });
37
38 it('should be trimmed', function () {
39 assert.equal(classNames('', 'b', {}, ''), 'b');
40 });
41
42 it('returns an empty string for an empty configuration', function () {
43 assert.equal(classNames({}), '');
44 });
45
46 it('supports an array of class names', function () {
47 assert.equal(classNames(['a', 'b']), 'a b');
48 });
49
50 it('joins array arguments with string arguments', function () {
51 assert.equal(classNames(['a', 'b'], 'c'), 'a b c');
52 assert.equal(classNames('c', ['a', 'b']), 'c a b');
53 });
54
55 it('handles multiple array arguments', function () {
56 assert.equal(classNames(['a', 'b'], ['c', 'd']), 'a b c d');
57 });
58
59 it('handles arrays that include falsy and true values', function () {
60 assert.equal(classNames(['a', 0, null, undefined, false, true, 'b']), 'a b');
61 });
62
63 it('handles arrays that include arrays', function () {
64 assert.equal(classNames(['a', ['b', 'c']]), 'a b c');
65 });
66
67 it('handles arrays that include objects', function () {
68 assert.equal(classNames(['a', {b: true, c: false}]), 'a b');
69 });
70
71 it('handles deep array recursion', function () {
72 assert.equal(classNames(['a', ['b', ['c', {d: true}]]]), 'a b c d');
73 });
74 });
75
76 describe('classNamesBound', function () {
77 it('keeps object keys with truthy values', function () {
78 assert.equal(classNamesBound({
79 a: true,
80 b: false,
81 c: 0,
82 d: null,
83 e: undefined,
84 f: 1
85 }), '#a #f');
86 });
87 it('keeps class names undefined in bound hash', function () {
88 assert.equal(classNamesBound({
89 a: true,
90 b: false,
91 c: 0,
92 d: null,
93 e: undefined,
94 f: 1,
95 x: true,
96 y: null,
97 z: 1
98 }), '#a #f x z');
99 })
100 it('joins arrays of class names and ignore falsy values', function () {
101 assert.equal(classNamesBound('a', 0, null, undefined, true, 1, 'b'), '#a 1 #b');
102 });
103
104 it('supports heterogenous arguments', function () {
105 assert.equal(classNamesBound({a: true}, 'b', 0), '#a #b');
106 });
107
108 it('should be trimmed', function () {
109 assert.equal(classNamesBound('', 'b', {}, ''), '#b');
110 });
111
112 it('returns an empty string for an empty configuration', function () {
113 assert.equal(classNamesBound({}), '');
114 });
115
116 it('supports an array of class names', function () {
117 assert.equal(classNamesBound(['a', 'b']), '#a #b');
118 });
119
120 it('joins array arguments with string arguments', function () {
121 assert.equal(classNamesBound(['a', 'b'], 'c'), '#a #b #c');
122 assert.equal(classNamesBound('c', ['a', 'b']), '#c #a #b');
123 });
124
125 it('handles multiple array arguments', function () {
126 assert.equal(classNamesBound(['a', 'b'], ['c', 'd']), '#a #b #c #d');
127 });
128
129 it('handles arrays that include falsy and true values', function () {
130 assert.equal(classNamesBound(['a', 0, null, undefined, false, true, 'b']), '#a #b');
131 });
132
133 it('handles arrays that include arrays', function () {
134 assert.equal(classNamesBound(['a', ['b', 'c']]), '#a #b #c');
135 });
136
137 it('handles arrays that include objects', function () {
138 assert.equal(classNamesBound(['a', {b: true, c: false}]), '#a #b');
139 });
140
141 it('handles deep array recursion', function () {
142 assert.equal(classNamesBound(['a', ['b', ['c', {d: true}]]]), '#a #b #c #d');
143 });
144 });
145
146})