-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
49 lines (40 loc) · 1.14 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
var test = require("tape");
var randomColor = require("./index.js");
test("returns color name when specified", function(t){
var options = {format: "name"},
color = randomColor(options),
regex = /^\w+$/;
t.ok(regex.test(color));
t.equals(typeof color, "string");
t.end();
});
test("returns color name when no options included", function(t){
var color = randomColor(),
regex = /^\w+$/;
t.ok(regex.test(color));
t.equals(typeof color, "string");
t.end();
});
test("returns rgb color", function(t){
var options = {format: "rgb"},
color = randomColor(options),
regex = /^rgb\(\w{1,3},\w{1,3},\w{1,3}\)$/;
t.ok(regex.test(color));
t.equals(typeof color, "string");
t.end();
});
test("returns hex color", function(t){
var options = {format: "hex"},
color = randomColor(options),
regex = /^#\w{6}$/;
t.ok(regex.test(color));
t.equals(typeof color, "string");
t.end();
});
test("throws TypeError", function(t){
var options = "some string";
t.throws(function(){
randomColor(options);
}, TypeError);
t.end();
});