-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.rgba.js
119 lines (109 loc) · 2.33 KB
/
test.rgba.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
/**
* 文件描述
* @author ydr.me
* @create 2018-04-26 09:03
* @update 2018-04-26 09:03
*/
'use strict';
var expect = require('chai-jasmine').expect;
var rgba = require('../../src/sources/rgba.js');
describe('rgba', function () {
it('.parse', function () {
expect(rgba.parse('rgb(255, 255, 255)')).toEqual({
r: 255,
g: 255,
b: 255,
a: 1
});
expect(function () {
rgba.parse('rgb(0, 0, 1, 1)');
}).toThrow();
expect(function () {
rgba.parse('rgba(0, 0, 1)');
}).toThrow();
});
it('.toHex', function () {
expect(rgba.toHex({
r: 255,
g: 255,
b: 255
})).toEqual('#ffffff');
expect(rgba.toHex({
r: 255,
g: 38,
b: 0
})).toEqual('#ff2600');
expect(rgba.toHex({
r: 1,
g: 22,
b: 123,
a: 1
})).toEqual('#01167b');
expect(rgba.toHex({
r: 1,
g: 3,
b: 5,
a: 0.7
})).toEqual('#010305b3');
});
it('.toHsl', function () {
expect(rgba.toHsla({
r: 255,
g: 255,
b: 255
})).toEqual({
h: 0,
s: 0,
l: 1,
a: 1
});
expect(rgba.toHsla({
r: 255,
g: 38,
b: 0
})).toEqual({
h: 8.941176470588236,
s: 1,
l: 0.5,
a: 1
});
expect(rgba.toHsla({
r: 255,
g: 0,
b: 0,
a: 0.5
})).toEqual({
h: 0,
s: 1,
l: 0.5,
a: 0.5
});
expect(rgba.toHsla({
r: 0,
g: 255,
b: 0
})).toEqual({
h: 120,
s: 1,
l: 0.5,
a: 1
});
expect(rgba.toHsla({
r: 0,
g: 0,
b: 255
})).toEqual({
h: 240,
s: 1,
l: 0.5,
a: 1
});
});
it('.stringify', function () {
expect(rgba.stringify({
r: 255,
g: 255,
b: 255
})).toEqual('rgb(255, 255, 255)');
});
});