-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.spec.js
53 lines (44 loc) · 1.94 KB
/
index.spec.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
var expect = require('chai').expect,
ColorGenerator = require('./index');
describe('rgba-generate', function(){
it('should generate an rgba value with a default opacity of 1', function(){
var colorGenerator = new ColorGenerator();
expect(colorGenerator).to.be.ok;
expect(colorGenerator()).to.match(/^rgba\(\d{1,3},\d{1,3},\d{1,3},1\)$/);
});
it('should respect the opacity constructor parameter', function(){
var colorGenerator = new ColorGenerator({opacity: .666});
expect(colorGenerator).to.be.ok;
expect(colorGenerator()).to.match(/^rgba\(\d{1,3},\d{1,3},\d{1,3},0\.666\)$/);
});
it('should respect the opacity function parameter', function(){
var colorGenerator = new ColorGenerator({opacity: .666});
expect(colorGenerator).to.be.ok;
expect(colorGenerator(.7)).to.match(/^rgba\(\d{1,3},\d{1,3},\d{1,3},0\.7\)$/);
});
it('should work with opacity zero as ctor param', function(){
var colorGenerator = new ColorGenerator({opacity: 0});
expect(colorGenerator).to.be.ok;
expect(colorGenerator()).to.match(/^rgba\(\d{1,3},\d{1,3},\d{1,3},0\)$/);
});
it('should work with opacity zero as function param', function(){
var colorGenerator = new ColorGenerator({opacity: .8});
expect(colorGenerator).to.be.ok;
expect(colorGenerator(0)).to.match(/^rgba\(\d{1,3},\d{1,3},\d{1,3},0\)$/);
});
it('should work without new', function(){
var colorGenerator = ColorGenerator({opacity: .8});
expect(colorGenerator).to.be.ok;
expect(colorGenerator(0)).to.match(/^rgba\(\d{1,3},\d{1,3},\d{1,3},0\)$/);
});
it('should work with just an opacity value passed to ctor', function(){
var colorGenerator = ColorGenerator(0.8);
expect(colorGenerator).to.be.ok;
expect(colorGenerator()).to.match(/^rgba\(\d{1,3},\d{1,3},\d{1,3},0.8\)$/);
});
it('should be able to convert to hex', function(){
var colorGenerator = ColorGenerator(0.8);
expect(colorGenerator).to.be.ok;
expect(colorGenerator().toHex()).to.match(/^#[a-f\d]{6}$/);
});
});