@@ -53,8 +53,8 @@ describe('js-to-styles-vars-loader', () => {
5353 } ) ;
5454 } ) ;
5555
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" , ( ) => {
5858 const areOk = [ { } , { a : "foo" } ] ;
5959 const areNotOk = [ [ ] , [ "a" ] , "" , "123" , 123 , false , true , null , undefined , NaN ] ;
6060 expect ( ( ) => {
@@ -69,7 +69,42 @@ describe('js-to-styles-vars-loader', () => {
6969 } , ) . toThrow ( ) ;
7070
7171 }
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 ( ) ;
72106
107+ }
73108 } )
74109 } ) ;
75110
@@ -159,18 +194,13 @@ describe('js-to-styles-vars-loader', () => {
159194 addDependency ( ) { }
160195 } ;
161196 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; }" ;
167198
168199 it ( 'inserts vars to styles content' , ( ) => {
169200 operator . mergeVarsToContent ( content , context , 'less' )
170201
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; }" ) ;
174204 } ) ;
175205
176206 it ( 'call context.addDependecy' , ( ) => {
0 commit comments