@@ -25,6 +25,20 @@ const THEMR_CONFIG = typeof Symbol !== 'undefined' ?
25
25
Symbol ( 'THEMR_CONFIG' ) :
26
26
'__REACT_CSS_THEMR_CONFIG__'
27
27
28
+ /**
29
+ * Add suppressReactErrorLogging = true to have no errors in the tests.
30
+ *
31
+ * @param {string } message error message that will be thrown
32
+ * @return {void }
33
+ */
34
+ const logErrorMessage = message => {
35
+ const error = new Error ( message )
36
+ if ( process . env . NODE_ENV === 'TESTING' ) {
37
+ error . suppressReactErrorLogging = true
38
+ }
39
+ throw error
40
+ }
41
+
28
42
/**
29
43
* Themr decorator
30
44
* @param {String|Number|Symbol } componentName - Component name
@@ -92,8 +106,11 @@ export default (componentName, localTheme, options = {}) => (ThemedComponent) =>
92
106
getNamespacedTheme ( props ) {
93
107
const { themeNamespace, theme } = props
94
108
if ( ! themeNamespace ) return theme
95
- if ( themeNamespace && ! theme ) throw new Error ( 'Invalid themeNamespace use in react-css-themr. ' +
109
+
110
+ if ( themeNamespace && ! theme ) {
111
+ logErrorMessage ( 'Invalid themeNamespace use in react-css-themr. ' +
96
112
'themeNamespace prop should be used only with theme prop.' )
113
+ }
97
114
98
115
return Object . keys ( theme )
99
116
. filter ( key => key . startsWith ( themeNamespace ) )
@@ -205,7 +222,7 @@ function merge(original = {}, mixin = {}) {
205
222
206
223
default : {
207
224
//can't merge an object with a non-object
208
- throw new Error ( `You are merging object ${ key } with a non-object ${ originalValue } ` )
225
+ logErrorMessage ( `You are merging object ${ key } with a non-object ${ originalValue } ` )
209
226
}
210
227
}
211
228
break
@@ -222,7 +239,8 @@ function merge(original = {}, mixin = {}) {
222
239
switch ( typeof originalValue ) {
223
240
case 'object' : {
224
241
//can't merge a non-object with an object
225
- throw new Error ( `You are merging non-object ${ mixinValue } with an object ${ key } ` )
242
+ logErrorMessage ( `You are merging non-object ${ mixinValue } with an object ${ key } ` )
243
+ break
226
244
}
227
245
228
246
case 'undefined' : {
@@ -261,7 +279,7 @@ function merge(original = {}, mixin = {}) {
261
279
*/
262
280
function validateComposeOption ( composeTheme ) {
263
281
if ( [ COMPOSE_DEEPLY , COMPOSE_SOFTLY , DONT_COMPOSE ] . indexOf ( composeTheme ) === - 1 ) {
264
- throw new Error (
282
+ logErrorMessage (
265
283
`Invalid composeTheme option for react-css-themr. Valid composition options\
266
284
are ${ COMPOSE_DEEPLY } , ${ COMPOSE_SOFTLY } and ${ DONT_COMPOSE } . The given\
267
285
option was ${ composeTheme } `
0 commit comments