11import formatProp from './formatProp' ;
22import formatPropValue from './formatPropValue' ;
3+
34jest . mock ( './formatPropValue' ) ;
5+
46const defaultOptions = {
57 useBooleanShorthandSyntax : true ,
68 tabStop : 2 ,
79} ;
10+
811describe ( 'formatProp' , ( ) => {
912 beforeEach ( ( ) => {
1013 jest . clearAllMocks ( ) ;
1114 jest . resetAllMocks ( ) ;
1215 } ) ;
16+
1317 it ( 'should format prop with only a value' , ( ) => {
1418 formatPropValue . mockReturnValue ( '"MockedPropValue"' ) ;
19+
1520 expect (
1621 formatProp ( 'foo' , true , 'bar' , false , null , true , 0 , defaultOptions )
1722 ) . toEqual ( {
@@ -20,15 +25,18 @@ describe('formatProp', () => {
2025 foo="MockedPropValue"` ,
2126 isMultilineAttribute : false ,
2227 } ) ;
28+
2329 expect ( formatPropValue ) . toHaveBeenCalledWith (
2430 'bar' ,
2531 true ,
2632 0 ,
2733 defaultOptions
2834 ) ;
2935 } ) ;
36+
3037 it ( 'should format prop with only a default value' , ( ) => {
3138 formatPropValue . mockReturnValue ( '"MockedPropValue"' ) ;
39+
3240 expect (
3341 formatProp ( 'foo' , false , null , true , 'baz' , true , 0 , defaultOptions )
3442 ) . toEqual ( {
@@ -37,15 +45,18 @@ describe('formatProp', () => {
3745 foo="MockedPropValue"` ,
3846 isMultilineAttribute : false ,
3947 } ) ;
48+
4049 expect ( formatPropValue ) . toHaveBeenCalledWith (
4150 'baz' ,
4251 true ,
4352 0 ,
4453 defaultOptions
4554 ) ;
4655 } ) ;
56+
4757 it ( 'should format prop with a value and a default value' , ( ) => {
4858 formatPropValue . mockReturnValue ( '"MockedPropValue"' ) ;
59+
4960 expect (
5061 formatProp ( 'foo' , true , 'bar' , true , 'baz' , true , 0 , defaultOptions )
5162 ) . toEqual ( {
@@ -54,19 +65,22 @@ describe('formatProp', () => {
5465 foo="MockedPropValue"` ,
5566 isMultilineAttribute : false ,
5667 } ) ;
68+
5769 expect ( formatPropValue ) . toHaveBeenCalledWith (
5870 'bar' ,
5971 true ,
6072 0 ,
6173 defaultOptions
6274 ) ;
6375 } ) ;
76+
6477 it ( 'should format a truthy boolean prop (with short syntax)' , ( ) => {
6578 const options = {
6679 useBooleanShorthandSyntax : true ,
6780 tabStop : 2 ,
6881 } ;
6982 formatPropValue . mockReturnValue ( '{true}' ) ;
83+
7084 expect (
7185 formatProp ( 'foo' , true , true , false , false , true , 0 , options )
7286 ) . toEqual ( {
@@ -75,29 +89,35 @@ describe('formatProp', () => {
7589 foo` ,
7690 isMultilineAttribute : false ,
7791 } ) ;
92+
7893 expect ( formatPropValue ) . toHaveBeenCalledWith ( true , true , 0 , options ) ;
7994 } ) ;
95+
8096 it ( 'should ignore a falsy boolean prop (with short syntax)' , ( ) => {
8197 const options = {
8298 useBooleanShorthandSyntax : true ,
8399 tabStop : 2 ,
84100 } ;
85101 formatPropValue . mockReturnValue ( '{false}' ) ;
102+
86103 expect (
87104 formatProp ( 'foo' , true , false , false , null , true , 0 , options )
88105 ) . toEqual ( {
89106 attributeFormattedInline : '' ,
90107 attributeFormattedMultiline : '' ,
91108 isMultilineAttribute : false ,
92109 } ) ;
110+
93111 expect ( formatPropValue ) . toHaveBeenCalledWith ( false , true , 0 , options ) ;
94112 } ) ;
113+
95114 it ( 'should format a truthy boolean prop (with explicit syntax)' , ( ) => {
96115 const options = {
97116 useBooleanShorthandSyntax : false ,
98117 tabStop : 2 ,
99118 } ;
100119 formatPropValue . mockReturnValue ( '{true}' ) ;
120+
101121 expect (
102122 formatProp ( 'foo' , true , true , false , false , true , 0 , options )
103123 ) . toEqual ( {
@@ -106,14 +126,17 @@ describe('formatProp', () => {
106126 foo={true}` ,
107127 isMultilineAttribute : false ,
108128 } ) ;
129+
109130 expect ( formatPropValue ) . toHaveBeenCalledWith ( true , true , 0 , options ) ;
110131 } ) ;
132+
111133 it ( 'should format a falsy boolean prop (with explicit syntax)' , ( ) => {
112134 const options = {
113135 useBooleanShorthandSyntax : false ,
114136 tabStop : 2 ,
115137 } ;
116138 formatPropValue . mockReturnValue ( '{false}' ) ;
139+
117140 expect (
118141 formatProp ( 'foo' , true , false , false , false , true , 0 , options )
119142 ) . toEqual ( {
@@ -122,13 +145,16 @@ describe('formatProp', () => {
122145 foo={false}` ,
123146 isMultilineAttribute : false ,
124147 } ) ;
148+
125149 expect ( formatPropValue ) . toHaveBeenCalledWith ( false , true , 0 , options ) ;
126150 } ) ;
151+
127152 it ( 'should format a mulitline props' , ( ) => {
128153 formatPropValue . mockReturnValue ( `{[
129154"a",
130155"b"
131156]}` ) ;
157+
132158 expect (
133159 formatProp (
134160 'foo' ,
@@ -152,13 +178,15 @@ describe('formatProp', () => {
152178]}` ,
153179 isMultilineAttribute : true ,
154180 } ) ;
181+
155182 expect ( formatPropValue ) . toHaveBeenCalledWith (
156183 [ 'a' , 'b' ] ,
157184 false ,
158185 0 ,
159186 defaultOptions
160187 ) ;
161188 } ) ;
189+
162190 it ( 'should indent the formatted string' , ( ) => {
163191 /*
164192 * lvl 4 and tabStop 2 :
@@ -171,6 +199,7 @@ describe('formatProp', () => {
171199 tabStop : 2 ,
172200 } ;
173201 formatPropValue . mockReturnValue ( '"MockedPropValue"' ) ;
202+
174203 expect (
175204 formatProp ( 'foo' , true , 'bar' , false , null , true , 4 , options )
176205 ) . toEqual ( {
@@ -180,6 +209,7 @@ describe('formatProp', () => {
180209 // 10 spaces
181210 isMultilineAttribute : false ,
182211 } ) ;
212+
183213 expect ( formatPropValue ) . toHaveBeenCalledWith ( 'bar' , true , 4 , options ) ;
184214 } ) ;
185215} ) ;
0 commit comments