This repository has been archived by the owner on Nov 20, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.test.js
80 lines (79 loc) · 2.08 KB
/
index.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
74
75
76
77
78
79
80
const objectToCss = require('./index');
describe('testing `createCssProperties(obj)`', () => {
test('removes last property its semicolon', () => {
expect(objectToCss.createCssProperties({
padding: "10px",
marginTop: "10px",
})).toBe("padding:10px;margin-top:10px");
});
test('hyphenates object keys', () => {
expect(objectToCss.createCssProperties({
marginTop: "10px",
})).toBe("margin-top:10px");
});
test('prepends `px` to number values', () => {
expect(objectToCss.createCssProperties({
padding: 10,
})).toBe("padding:10px");
});
test('does not modify string values even when string is numeric', () => {
expect(objectToCss.createCssProperties({
padding: '0',
})).toBe("padding:0");
});
test('works with multiple properties', () => {
expect(objectToCss.createCssProperties({
padding: 10,
margin: '20px',
borderTopWidth: '0',
})).toBe("padding:10px;margin:20px;border-top-width:0");
});
test('returns empty string without any properties', () => {
expect(objectToCss.createCssProperties({})).toBe("");
});
});
describe('testing `createCssRule(obj)', () => {
test('creates a single css rule', () => {
expect(objectToCss.createCssRule({
'.test': {
padding: 10,
},
})).toBe(".test{padding:10px}");
});
test('creates multiple css classes', () => {
expect(objectToCss.createCssRule({
'.test': {
padding: 10,
},
'#foo': {
padding: 10,
},
'#foo .bar': {
padding: 10,
},
})).toBe(".test{padding:10px}#foo{padding:10px}#foo .bar{padding:10px}");
});
test('does not create classes when class has no properties', () => {
expect(objectToCss.createCssRule({
'.test': {},
})).toBe("");
});
});
describe('testing `createCssClasses(obj)', () => {
test('prepends dot to key name', () => {
expect(objectToCss.createCssClasses({
test: {
padding: 10,
},
})).toBe(".test{padding:10px}");
});
});
describe('testing `createCssIdentifiers(obj)', () => {
test('prepends hashtag to key name', () => {
expect(objectToCss.createCssIdentifiers({
test: {
padding: 10,
},
})).toBe("#test{padding:10px}");
});
});