-
Notifications
You must be signed in to change notification settings - Fork 2
/
test.js
73 lines (60 loc) · 1.8 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
67
68
69
70
71
72
73
process.env.NODE_ENV = 'production';
const cssmem = require('.');
const test = (name, received, expected) => {
if (received !== expected) {
throw new Error(`
${name}:
Received: ${received}
Expected: ${expected}
`);
}
console.log(`${name} is OK`);
};
const styles = {
foo: 'm_foo',
foo_bar: 'm_foo_bar',
foo_baz_qwe: 'm_foo_baz_qwe',
'foo--bar': 'm_foo--bar',
'foo--baz-qwe': 'm_foo--baz-qwe',
};
const em = cssmem(styles);
const foo = em('foo');
test('Just elem', foo(), 'm_foo');
test('Elem with bool mod', foo({ bar: true }), 'm_foo m_foo_bar');
test('Elem with mod', foo({ baz: 'qwe' }), 'm_foo m_foo_baz_qwe');
test(
'Elem with two mods',
foo({ bar: true, baz: 'qwe' }),
'm_foo m_foo_bar m_foo_baz_qwe'
);
test('Elem with mod which not exist', foo({ zxc: true }), 'm_foo');
test('Elem with bool mod which not bool', foo({ baz: true }), 'm_foo');
test('Elem with not bool mod which bool', foo({ bar: 'qwe' }), 'm_foo');
test(
'Elem with two mods and one is bool mod which not bool',
foo({ baz: true, bar: true }),
'm_foo m_foo_bar'
);
test(
'Elem with two mods and one is not bool mod which bool',
foo({ bar: 'qwe', baz: 'qwe' }),
'm_foo m_foo_baz_qwe'
);
test('Elem not found', em('bar')(), '');
test('Mix with elem', foo({}, 'mixed'), 'm_foo mixed');
test('Mix with array', foo({}, ['mixed', 'fixed']), 'm_foo mixed fixed');
test('Mix with null mod', foo(null, 'mixed'), 'm_foo mixed');
test('Mix with mod', foo({ bar: true }, 'mixed'), 'm_foo m_foo_bar mixed');
cssmem.config.elemDelimiter = '--';
cssmem.config.modDelimiter = '-';
test(
'Elem with custom delimiter and bool mod',
foo({ bar: true }),
'm_foo m_foo--bar'
);
test(
'Elem with custom delimiter and mod',
foo({ baz: 'qwe' }),
'm_foo m_foo--baz-qwe'
);
console.log('\nAll test passed!');