@@ -23,7 +23,6 @@ describe('js-to-styles-vars-loader', () => {
23
23
spyOn ( operator , 'getResource' ) . and . callThrough ( ) ;
24
24
loader . call ( context , 'asdf' ) ;
25
25
expect ( operator . getResource ) . toHaveBeenCalledWith ( context ) ;
26
-
27
26
} ) ;
28
27
29
28
it ( 'calls getPreprocessorType with resource' , ( ) => {
@@ -54,7 +53,23 @@ describe('js-to-styles-vars-loader', () => {
54
53
} ) ;
55
54
} ) ;
56
55
57
-
56
+ describe ( 'guardExportType' , ( ) => {
57
+ it ( "throws on anything except an object, does not throw otherwise" , ( ) => {
58
+ const areOk = [ { } , { a : "foo" } ] ;
59
+ const areNotOk = [ [ ] , [ "a" ] , "" , "123" , 123 , false , true ] ;
60
+ expect ( ( ) => {
61
+ for ( const okThing of areOk ) {
62
+ operator . guardExportType ( okThing , "" ) ;
63
+ }
64
+ } ) . not . toThrow ( ) ;
65
+ for ( const okThing of areNotOk ) {
66
+ expect ( ( ) => {
67
+ operator . guardExportType ( okThing , "" ) ;
68
+ } ) . toThrow ( ) ;
69
+ }
70
+
71
+ } )
72
+ } ) ;
58
73
59
74
describe ( 'getVarData' , ( ) => {
60
75
const context = {
@@ -75,6 +90,51 @@ describe('js-to-styles-vars-loader', () => {
75
90
const varData = operator . getVarData ( path . join ( context . context , './mocks/corners.js' ) , 'deep.nested' ) ;
76
91
expect ( varData ) . toEqual ( { color : '#f00' } ) ;
77
92
} ) ;
93
+
94
+ it ( 'throws on an missing module' , ( ) => {
95
+ expect ( ( ) => {
96
+ operator . getVarData ( path . join ( context . context , './mocks/this_is_not_an_existing_file.js' ) ) ;
97
+ } ) . toThrow ( ) ;
98
+ } )
99
+ it ( 'throws on a non-object export' , ( ) => {
100
+ expect ( ( ) => {
101
+ operator . getVarData ( path . join ( context . context , './mocks/null_export.js' ) ) ;
102
+ } ) . toThrow ( ) ;
103
+ } )
104
+
105
+
106
+
107
+ it ( 'throws on an empty property' , ( ) => {
108
+ expect ( ( ) => {
109
+ operator . getVarData ( path . join ( context . context , './mocks/bad_exports.js' ) , 'empty' ) ;
110
+ } ) . toThrow ( ) ;
111
+ expect ( ( ) => {
112
+ operator . getVarData ( path . join ( context . context , './mocks/bad_exports.js' ) , 'notEmptyObject' ) ;
113
+ } ) . not . toThrow ( ) ;
114
+ } )
115
+
116
+ it ( 'does not throw on an empty object' , ( ) => {
117
+ expect ( ( ) => {
118
+ operator . getVarData ( path . join ( context . context , './mocks/bad_exports.js' ) , 'emptyObject' ) ;
119
+ } ) . not . toThrow ( ) ;
120
+ } )
121
+
122
+ it ( 'throws on a non-object property' , ( ) => {
123
+ expect ( ( ) => {
124
+ operator . getVarData ( path . join ( context . context , './mocks/bad_exports.js' ) , 'falsey' ) ;
125
+ } ) . toThrow ( ) ;
126
+ expect ( ( ) => {
127
+ operator . getVarData ( path . join ( context . context , './mocks/bad_exports.js' ) , 'truthy' ) ;
128
+ } ) . toThrow ( ) ;
129
+ expect ( ( ) => {
130
+ operator . getVarData ( path . join ( context . context , './mocks/bad_exports.js' ) , 'emptyArray' ) ;
131
+ } ) . toThrow ( ) ;
132
+ expect ( ( ) => {
133
+ operator . getVarData ( path . join ( context . context , './mocks/bad_exports.js' ) , 'nonEmptyArray' ) ;
134
+ } ) . toThrow ( ) ;
135
+
136
+ } )
137
+
78
138
} ) ;
79
139
80
140
describe ( 'transformToSassVars' , ( ) => {
0 commit comments