This repository has been archived by the owner on Jul 29, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
/
index.test.ts
100 lines (87 loc) · 4.83 KB
/
index.test.ts
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
import { svgrOptionsFromQuery } from '.';
test('empty query', () => {
expect(svgrOptionsFromQuery('component')).toStrictEqual({});
});
test('single boolean options', () => {
expect(svgrOptionsFromQuery('component&ref')).toStrictEqual({ ref: true });
expect(svgrOptionsFromQuery('component&ref=true')).toStrictEqual({ ref: true });
expect(svgrOptionsFromQuery('component&ref=false')).toStrictEqual({ ref: false });
expect(() => svgrOptionsFromQuery('component&ref=yes')).toThrow();
expect(svgrOptionsFromQuery('component&icon')).toStrictEqual({ icon: true });
expect(svgrOptionsFromQuery('component&icon=true')).toStrictEqual({ icon: true });
expect(svgrOptionsFromQuery('component&icon=false')).toStrictEqual({ icon: false });
expect(() => svgrOptionsFromQuery('component&icon=yes')).toThrow();
expect(svgrOptionsFromQuery('component&svgo')).toStrictEqual({ svgo: true });
expect(svgrOptionsFromQuery('component&svgo=true')).toStrictEqual({ svgo: true });
expect(svgrOptionsFromQuery('component&svgo=false')).toStrictEqual({ svgo: false });
expect(() => svgrOptionsFromQuery('component&svgo=yes')).toThrow();
expect(svgrOptionsFromQuery('component&memo')).toStrictEqual({ memo: true });
expect(svgrOptionsFromQuery('component&memo=true')).toStrictEqual({ memo: true });
expect(svgrOptionsFromQuery('component&memo=false')).toStrictEqual({ memo: false });
expect(() => svgrOptionsFromQuery('component&memo=yes')).toThrow();
expect(svgrOptionsFromQuery('component&titleProp')).toStrictEqual({ titleProp: true });
expect(svgrOptionsFromQuery('component&titleProp=true')).toStrictEqual({ titleProp: true });
expect(svgrOptionsFromQuery('component&titleProp=false')).toStrictEqual({ titleProp: false });
expect(() => svgrOptionsFromQuery('component&titleProp=yes')).toThrow();
expect(svgrOptionsFromQuery('component&dimensions')).toStrictEqual({ dimensions: true });
expect(svgrOptionsFromQuery('component&dimensions=true')).toStrictEqual({ dimensions: true });
expect(svgrOptionsFromQuery('component&dimensions=false')).toStrictEqual({ dimensions: false });
expect(() => svgrOptionsFromQuery('component&dimensions=yes')).toThrow();
});
test('multiple boolean options', () => {
expect(svgrOptionsFromQuery('component&icon&dimensions')).toStrictEqual({ icon: true, dimensions: true });
expect(svgrOptionsFromQuery('component&icon=false&dimensions')).toStrictEqual({ icon: false, dimensions: true });
expect(svgrOptionsFromQuery('component&icon&dimensions=false')).toStrictEqual({ icon: true, dimensions: false });
expect(svgrOptionsFromQuery('component&icon=false&dimensions=false')).toStrictEqual({
icon: false,
dimensions: false
});
});
test('expandProps option', () => {
expect(svgrOptionsFromQuery('component&expandProps=start')).toStrictEqual({ expandProps: 'start' });
expect(svgrOptionsFromQuery('component&expandProps=end')).toStrictEqual({ expandProps: 'end' });
expect(svgrOptionsFromQuery('component&expandProps=false')).toStrictEqual({ expandProps: false });
expect(() => svgrOptionsFromQuery('component&expandProps=yes')).toThrow();
expect(() => svgrOptionsFromQuery('component&expandProps')).toThrow();
});
test('single key/value options', () => {
expect(() => svgrOptionsFromQuery('component&svgProps')).toThrow();
expect(() => svgrOptionsFromQuery('component&svgProps=height')).toThrow();
expect(() => svgrOptionsFromQuery('component&replaceAttrValues')).toThrow();
expect(() => svgrOptionsFromQuery('component&replaceAttrValues=color')).toThrow();
expect(svgrOptionsFromQuery('component&svgProps=height:80')).toStrictEqual({ svgProps: { height: '80' } });
expect(svgrOptionsFromQuery('component&replaceAttrValues=color:white')).toStrictEqual({
replaceAttrValues: { color: 'white' }
});
});
test('multiple key/value options', () => {
expect(svgrOptionsFromQuery('component&svgProps=height:80&svgProps=width:150')).toStrictEqual({
svgProps: { height: '80', width: '150' }
});
expect(
svgrOptionsFromQuery('component&replaceAttrValues=color:white&replaceAttrValues=viewBox:0 0 20 20')
).toStrictEqual({
replaceAttrValues: { color: 'white', viewBox: '0 0 20 20' }
});
});
test('multiple mixed options', () => {
expect(
svgrOptionsFromQuery(
'component&icon&dimensions=false&svgProps=height:80&svgProps=width:150&replaceAttrValues=color:white'
)
).toStrictEqual({
icon: true,
dimensions: false,
svgProps: {
height: '80',
width: '150'
},
replaceAttrValues: {
color: 'white'
}
});
});
test('invalid option', () => {
expect(() => svgrOptionsFromQuery('component&typescript')).toThrow();
expect(() => svgrOptionsFromQuery('component&typescript=true')).toThrow();
});