@@ -25,6 +25,20 @@ const THEMR_CONFIG = typeof Symbol !== 'undefined' ?
2525 Symbol ( 'THEMR_CONFIG' ) :
2626 '__REACT_CSS_THEMR_CONFIG__'
2727
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+
2842/**
2943 * Themr decorator
3044 * @param {String|Number|Symbol } componentName - Component name
@@ -92,8 +106,11 @@ export default (componentName, localTheme, options = {}) => (ThemedComponent) =>
92106 getNamespacedTheme ( props ) {
93107 const { themeNamespace, theme } = props
94108 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. ' +
96112 'themeNamespace prop should be used only with theme prop.' )
113+ }
97114
98115 return Object . keys ( theme )
99116 . filter ( key => key . startsWith ( themeNamespace ) )
@@ -205,7 +222,7 @@ function merge(original = {}, mixin = {}) {
205222
206223 default : {
207224 //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 } ` )
209226 }
210227 }
211228 break
@@ -222,7 +239,8 @@ function merge(original = {}, mixin = {}) {
222239 switch ( typeof originalValue ) {
223240 case 'object' : {
224241 //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
226244 }
227245
228246 case 'undefined' : {
@@ -261,7 +279,7 @@ function merge(original = {}, mixin = {}) {
261279 */
262280function validateComposeOption ( composeTheme ) {
263281 if ( [ COMPOSE_DEEPLY , COMPOSE_SOFTLY , DONT_COMPOSE ] . indexOf ( composeTheme ) === - 1 ) {
264- throw new Error (
282+ logErrorMessage (
265283 `Invalid composeTheme option for react-css-themr. Valid composition options\
266284 are ${ COMPOSE_DEEPLY } , ${ COMPOSE_SOFTLY } and ${ DONT_COMPOSE } . The given\
267285 option was ${ composeTheme } `
0 commit comments