Skip to content

Commit 0246956

Browse files
author
Markus Günther
committed
TASK: Disable console.error in tests instead of suppressReactErrorLogging
1 parent fef61df commit 0246956

File tree

2 files changed

+14
-18
lines changed

2 files changed

+14
-18
lines changed

src/components/themr.js

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -25,20 +25,6 @@ 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-
4228
/**
4329
* Themr decorator
4430
* @param {String|Number|Symbol} componentName - Component name
@@ -108,7 +94,7 @@ export default (componentName, localTheme, options = {}) => (ThemedComponent) =>
10894
if (!themeNamespace) return theme
10995

11096
if (themeNamespace && !theme) {
111-
logErrorMessage('Invalid themeNamespace use in react-css-themr. ' +
97+
throw new Error('Invalid themeNamespace use in react-css-themr. ' +
11298
'themeNamespace prop should be used only with theme prop.')
11399
}
114100

@@ -222,7 +208,7 @@ function merge(original = {}, mixin = {}) {
222208

223209
default: {
224210
//can't merge an object with a non-object
225-
logErrorMessage(`You are merging object ${key} with a non-object ${originalValue}`)
211+
throw new Error(`You are merging object ${key} with a non-object ${originalValue}`)
226212
}
227213
}
228214
break
@@ -239,7 +225,7 @@ function merge(original = {}, mixin = {}) {
239225
switch (typeof originalValue) {
240226
case 'object': {
241227
//can't merge a non-object with an object
242-
logErrorMessage(`You are merging non-object ${mixinValue} with an object ${key}`)
228+
throw new Error(`You are merging non-object ${mixinValue} with an object ${key}`)
243229
break
244230
}
245231

@@ -279,7 +265,7 @@ function merge(original = {}, mixin = {}) {
279265
*/
280266
function validateComposeOption(composeTheme) {
281267
if ([ COMPOSE_DEEPLY, COMPOSE_SOFTLY, DONT_COMPOSE ].indexOf(composeTheme) === -1) {
282-
logErrorMessage(
268+
throw new Error(
283269
`Invalid composeTheme option for react-css-themr. Valid composition options\
284270
are ${COMPOSE_DEEPLY}, ${COMPOSE_SOFTLY} and ${DONT_COMPOSE}. The given\
285271
option was ${composeTheme}`

test/components/ThemeProvider.spec.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,16 @@ import PropTypes from 'prop-types'
44
import TestUtils from 'react-dom/test-utils'
55
import { ThemeProvider } from '../../src/index'
66

7+
8+
before(function () {
9+
/* eslint-disable no-console */
10+
console.error = function () {}
11+
})
12+
13+
after(function () {
14+
delete console.error
15+
})
16+
717
describe('ThemeProvider', () => {
818
class Child extends Component {
919
render() {

0 commit comments

Comments
 (0)