1
1
import formatProp from './formatProp' ;
2
2
import formatPropValue from './formatPropValue' ;
3
+
3
4
jest . mock ( './formatPropValue' ) ;
5
+
4
6
const defaultOptions = {
5
7
useBooleanShorthandSyntax : true ,
6
8
tabStop : 2 ,
7
9
} ;
10
+
8
11
describe ( 'formatProp' , ( ) => {
9
12
beforeEach ( ( ) => {
10
13
jest . clearAllMocks ( ) ;
11
14
jest . resetAllMocks ( ) ;
12
15
} ) ;
16
+
13
17
it ( 'should format prop with only a value' , ( ) => {
14
18
formatPropValue . mockReturnValue ( '"MockedPropValue"' ) ;
19
+
15
20
expect (
16
21
formatProp ( 'foo' , true , 'bar' , false , null , true , 0 , defaultOptions )
17
22
) . toEqual ( {
@@ -20,15 +25,18 @@ describe('formatProp', () => {
20
25
foo="MockedPropValue"` ,
21
26
isMultilineAttribute : false ,
22
27
} ) ;
28
+
23
29
expect ( formatPropValue ) . toHaveBeenCalledWith (
24
30
'bar' ,
25
31
true ,
26
32
0 ,
27
33
defaultOptions
28
34
) ;
29
35
} ) ;
36
+
30
37
it ( 'should format prop with only a default value' , ( ) => {
31
38
formatPropValue . mockReturnValue ( '"MockedPropValue"' ) ;
39
+
32
40
expect (
33
41
formatProp ( 'foo' , false , null , true , 'baz' , true , 0 , defaultOptions )
34
42
) . toEqual ( {
@@ -37,15 +45,18 @@ describe('formatProp', () => {
37
45
foo="MockedPropValue"` ,
38
46
isMultilineAttribute : false ,
39
47
} ) ;
48
+
40
49
expect ( formatPropValue ) . toHaveBeenCalledWith (
41
50
'baz' ,
42
51
true ,
43
52
0 ,
44
53
defaultOptions
45
54
) ;
46
55
} ) ;
56
+
47
57
it ( 'should format prop with a value and a default value' , ( ) => {
48
58
formatPropValue . mockReturnValue ( '"MockedPropValue"' ) ;
59
+
49
60
expect (
50
61
formatProp ( 'foo' , true , 'bar' , true , 'baz' , true , 0 , defaultOptions )
51
62
) . toEqual ( {
@@ -54,19 +65,22 @@ describe('formatProp', () => {
54
65
foo="MockedPropValue"` ,
55
66
isMultilineAttribute : false ,
56
67
} ) ;
68
+
57
69
expect ( formatPropValue ) . toHaveBeenCalledWith (
58
70
'bar' ,
59
71
true ,
60
72
0 ,
61
73
defaultOptions
62
74
) ;
63
75
} ) ;
76
+
64
77
it ( 'should format a truthy boolean prop (with short syntax)' , ( ) => {
65
78
const options = {
66
79
useBooleanShorthandSyntax : true ,
67
80
tabStop : 2 ,
68
81
} ;
69
82
formatPropValue . mockReturnValue ( '{true}' ) ;
83
+
70
84
expect (
71
85
formatProp ( 'foo' , true , true , false , false , true , 0 , options )
72
86
) . toEqual ( {
@@ -75,29 +89,35 @@ describe('formatProp', () => {
75
89
foo` ,
76
90
isMultilineAttribute : false ,
77
91
} ) ;
92
+
78
93
expect ( formatPropValue ) . toHaveBeenCalledWith ( true , true , 0 , options ) ;
79
94
} ) ;
95
+
80
96
it ( 'should ignore a falsy boolean prop (with short syntax)' , ( ) => {
81
97
const options = {
82
98
useBooleanShorthandSyntax : true ,
83
99
tabStop : 2 ,
84
100
} ;
85
101
formatPropValue . mockReturnValue ( '{false}' ) ;
102
+
86
103
expect (
87
104
formatProp ( 'foo' , true , false , false , null , true , 0 , options )
88
105
) . toEqual ( {
89
106
attributeFormattedInline : '' ,
90
107
attributeFormattedMultiline : '' ,
91
108
isMultilineAttribute : false ,
92
109
} ) ;
110
+
93
111
expect ( formatPropValue ) . toHaveBeenCalledWith ( false , true , 0 , options ) ;
94
112
} ) ;
113
+
95
114
it ( 'should format a truthy boolean prop (with explicit syntax)' , ( ) => {
96
115
const options = {
97
116
useBooleanShorthandSyntax : false ,
98
117
tabStop : 2 ,
99
118
} ;
100
119
formatPropValue . mockReturnValue ( '{true}' ) ;
120
+
101
121
expect (
102
122
formatProp ( 'foo' , true , true , false , false , true , 0 , options )
103
123
) . toEqual ( {
@@ -106,14 +126,17 @@ describe('formatProp', () => {
106
126
foo={true}` ,
107
127
isMultilineAttribute : false ,
108
128
} ) ;
129
+
109
130
expect ( formatPropValue ) . toHaveBeenCalledWith ( true , true , 0 , options ) ;
110
131
} ) ;
132
+
111
133
it ( 'should format a falsy boolean prop (with explicit syntax)' , ( ) => {
112
134
const options = {
113
135
useBooleanShorthandSyntax : false ,
114
136
tabStop : 2 ,
115
137
} ;
116
138
formatPropValue . mockReturnValue ( '{false}' ) ;
139
+
117
140
expect (
118
141
formatProp ( 'foo' , true , false , false , false , true , 0 , options )
119
142
) . toEqual ( {
@@ -122,13 +145,16 @@ describe('formatProp', () => {
122
145
foo={false}` ,
123
146
isMultilineAttribute : false ,
124
147
} ) ;
148
+
125
149
expect ( formatPropValue ) . toHaveBeenCalledWith ( false , true , 0 , options ) ;
126
150
} ) ;
151
+
127
152
it ( 'should format a mulitline props' , ( ) => {
128
153
formatPropValue . mockReturnValue ( `{[
129
154
"a",
130
155
"b"
131
156
]}` ) ;
157
+
132
158
expect (
133
159
formatProp (
134
160
'foo' ,
@@ -152,13 +178,15 @@ describe('formatProp', () => {
152
178
]}` ,
153
179
isMultilineAttribute : true ,
154
180
} ) ;
181
+
155
182
expect ( formatPropValue ) . toHaveBeenCalledWith (
156
183
[ 'a' , 'b' ] ,
157
184
false ,
158
185
0 ,
159
186
defaultOptions
160
187
) ;
161
188
} ) ;
189
+
162
190
it ( 'should indent the formatted string' , ( ) => {
163
191
/*
164
192
* lvl 4 and tabStop 2 :
@@ -171,6 +199,7 @@ describe('formatProp', () => {
171
199
tabStop : 2 ,
172
200
} ;
173
201
formatPropValue . mockReturnValue ( '"MockedPropValue"' ) ;
202
+
174
203
expect (
175
204
formatProp ( 'foo' , true , 'bar' , false , null , true , 4 , options )
176
205
) . toEqual ( {
@@ -180,6 +209,7 @@ describe('formatProp', () => {
180
209
// 10 spaces
181
210
isMultilineAttribute : false ,
182
211
} ) ;
212
+
183
213
expect ( formatPropValue ) . toHaveBeenCalledWith ( 'bar' , true , 4 , options ) ;
184
214
} ) ;
185
215
} ) ;
0 commit comments