@@ -53,8 +53,8 @@ describe('js-to-styles-vars-loader', () => {
53
53
} ) ;
54
54
} ) ;
55
55
56
- describe ( 'validateExportType ' , ( ) => {
57
- it ( "throws on anything except an object, does not throw otherwise" , ( ) => {
56
+ describe ( 'validation ' , ( ) => {
57
+ it ( "validateExportType() throws on anything except an object, does not throw otherwise" , ( ) => {
58
58
const areOk = [ { } , { a : "foo" } ] ;
59
59
const areNotOk = [ [ ] , [ "a" ] , "" , "123" , 123 , false , true , null , undefined , NaN ] ;
60
60
expect ( ( ) => {
@@ -69,7 +69,42 @@ describe('js-to-styles-vars-loader', () => {
69
69
} , ) . toThrow ( ) ;
70
70
71
71
}
72
+ } )
73
+
74
+ it ( "validateVariablesValue() throws on nested objects or invalid object property values" , ( ) => {
75
+ const areOk = [
76
+ { a : "foo" } ,
77
+ { a : 100.1 } ,
78
+ { a : 100 } ,
79
+ { a : "" } ,
80
+ { a : 0 } ,
81
+ { a : 0 } ,
82
+ { } ,
83
+ ] ;
84
+ const areNotOk = [
85
+ { a : 1 / "bad" } ,
86
+ { b : [ ] } ,
87
+ { c : [ "bad" ] } ,
88
+ { d : [ 100.1 ] } ,
89
+ { e : ( ) => "bad" } ,
90
+ { f : { } } ,
91
+ { g : { b : "bad" } } ,
92
+ { h : "foo" , b : { } } ,
93
+ { i : "foo" , b : { c : "bad" } } ,
94
+ { j : "foo" , b : { c : 100 } }
95
+ ] ;
96
+ expect ( ( ) => {
97
+ for ( const okThing of areOk ) {
98
+ operator . validateVariablesValue ( okThing , "" ) ;
99
+ }
100
+ } ) . not . toThrow ( ) ;
101
+ for ( const notOkThing of areNotOk ) {
102
+ expect ( ( ) => {
103
+ operator . validateVariablesValue ( notOkThing , "" , "" ) ;
104
+ console . error ( `Should have thrown on ${ typeof notOkThing } '${ JSON . stringify ( notOkThing ) } '` ) ;
105
+ } , ) . toThrow ( ) ;
72
106
107
+ }
73
108
} )
74
109
} ) ;
75
110
@@ -159,18 +194,13 @@ describe('js-to-styles-vars-loader', () => {
159
194
addDependency ( ) { }
160
195
} ;
161
196
const content = "require('./mocks/colors.js');\n" +
162
- ".someClass { color: #fff;}" ;
163
-
164
- const trimmer = ( str ) => {
165
- return ( str . split ( "\n" ) . filter ( a => a ) . map ( s => s . trim ( ) ) . join ( " " ) ) . trim ( )
166
- } ;
197
+ ".someClass { color: #fff; }" ;
167
198
168
199
it ( 'inserts vars to styles content' , ( ) => {
169
200
operator . mergeVarsToContent ( content , context , 'less' )
170
201
171
- expect ( trimmer ( operator . mergeVarsToContent ( content , context , 'less' ) ) ) . toEqual ( trimmer ( `
172
- @white: #fff; @black: #000; .someClass { color: #fff;}
173
- ` ) ) ;
202
+ expect ( operator . mergeVarsToContent ( content , context , 'less' ) )
203
+ . toEqual ( "@white: #fff;\n@black: #000;\n\n.someClass { color: #fff; }" ) ;
174
204
} ) ;
175
205
176
206
it ( 'call context.addDependecy' , ( ) => {
0 commit comments