-
Notifications
You must be signed in to change notification settings - Fork 6
/
test.js
66 lines (52 loc) · 2.18 KB
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
var assert = require('assert');
var cx = require('./');
describe('cx', function() {
var classes = {
name: 'button',
modifiers: ['color', 'block'],
states: ['loading', 'disabled']
};
it('should return empty string', function() {
assert.equal(cx(), '');
});
it('should return block name', function() {
assert.equal(cx(classes), 'button');
});
it('should return modifiers', function() {
assert.equal(cx(classes, { color: 'green' }), 'button button--green');
assert.equal(cx(classes, { color: 'green', block: true }), 'button button--green button--block');
assert.equal(cx(classes, { color: 'green' }, { block: true }), 'button button--green button--block');
});
it('should return states', function() {
assert.equal(cx(classes, { loading: true }), 'button is-loading');
assert.equal(cx(classes, { loading: true, disabled: true }), 'button is-loading is-disabled');
assert.equal(cx(classes, { loading: true }, { disabled: true }), 'button is-loading is-disabled');
});
it('supports a string of class names', function() {
assert.equal(cx({ name: 'button' }, 'a'), 'button a');
assert.equal(cx(classes, 'a'), 'button a');
assert.equal(cx(classes, 'a', 'b c'), 'button a b c');
});
it('supports an array of class names', function() {
assert.equal(cx(classes, ['a']), 'button a');
assert.equal(cx(classes, ['a'], ['b', 'c']), 'button a b c');
});
it('should ignore, except for valid objects', function() {
assert.equal(cx(classes, null, undefined, 1, 0, true, false, '', { color: 'green' }, 'a', ['b', 'c']), 'button button--green a b c');
});
it('should be trimmed', function() {
assert.equal(cx(classes, '', ' b ', [' ']), 'button b');
});
it('should dedupe', function() {
assert.equal(cx(classes, 'foo', 'bar', 'foo', 'bar'), 'button foo bar');
});
it('should be custom prefixes', function() {
cx.prefixes.modifiers = '-';
assert.equal(cx(classes, { color: 'green', block: true }), 'button -green -block');
});
it('should be custom rules', function() {
cx.prefixes.foo = 'foo-';
classes.foo = ['a', 'b'];
assert.equal(cx(classes, { a: true, b: true }), 'button foo-a foo-b');
});
});