-
Notifications
You must be signed in to change notification settings - Fork 103
Expand file tree
/
Copy pathinlineStyleToObject.spec.js
More file actions
53 lines (45 loc) · 1.85 KB
/
inlineStyleToObject.spec.js
File metadata and controls
53 lines (45 loc) · 1.85 KB
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
import inlineStyleToObject from 'utils/inlineStyleToObject';
describe('Testing `utils/inlineStyleToObject', () => {
it('should return an empty object if the inline style is empty', () => {
expect(inlineStyleToObject()).toEqual({});
expect(inlineStyleToObject('')).toEqual({});
});
it('should camelise each style whenever there is a hyphen', () => {
const inlineStyle = 'text-decoration:none;-webkit-border-radius:5px;';
const expectedStyleObject = {
textDecoration: 'none',
'WebkitBorderRadius': '5px'
};
expect(inlineStyleToObject(inlineStyle)).toEqual(expectedStyleObject);
});
it('should ignore invalid style properties', () => {
const inlineStyle = 'font-color:red;invalid;color:blue;';
const expectedStyleObject = {
fontColor: 'red',
color: 'blue'
};
expect(inlineStyleToObject(inlineStyle)).toEqual(expectedStyleObject);
});
it('should not upper case the beginning `m` when using the `-ms-` vendor prefix', () => {
const inlineStyle = '-ms-border-radius:10px';
const expectedStyleObject = {
'msBorderRadius': '10px'
};
expect(inlineStyleToObject(inlineStyle)).toEqual(expectedStyleObject);
});
it('should parse styles containing multiple colons correctly', () => {
const inlineStyle = 'background:url(https://test.com/image.png);color:white;';
const expectedStyleObject = {
background: 'url(https://test.com/image.png)',
color: 'white'
};
expect(inlineStyleToObject(inlineStyle)).toEqual(expectedStyleObject);
});
it('should parse style values containing upper-case characters correctly', () => {
const inlineStyle = 'background:url(https://test.com/IMAGE.png);';
const expectedStyleObject = {
background: 'url(https://test.com/IMAGE.png)',
};
expect(inlineStyleToObject(inlineStyle)).toEqual(expectedStyleObject);
});
});