File tree Expand file tree Collapse file tree 4 files changed +65
-11
lines changed Expand file tree Collapse file tree 4 files changed +65
-11
lines changed Original file line number Diff line number Diff line change @@ -2,8 +2,7 @@ import { ActionTypes } from './createStore'
2
2
import isPlainObject from './utils/isPlainObject'
3
3
import mapValues from './utils/mapValues'
4
4
import pick from './utils/pick'
5
-
6
- /* eslint-disable no-console */
5
+ import warning from './utils/warning'
7
6
8
7
function getUndefinedStateErrorMessage ( key , action ) {
9
8
var actionType = action && action . type
@@ -112,7 +111,7 @@ export default function combineReducers(reducers) {
112
111
if ( process . env . NODE_ENV !== 'production' ) {
113
112
var warningMessage = getUnexpectedStateShapeWarningMessage ( state , finalReducers , action )
114
113
if ( warningMessage ) {
115
- console . error ( warningMessage )
114
+ warning ( warningMessage )
116
115
}
117
116
}
118
117
Original file line number Diff line number Diff line change @@ -3,6 +3,7 @@ import combineReducers from './combineReducers'
3
3
import bindActionCreators from './bindActionCreators'
4
4
import applyMiddleware from './applyMiddleware'
5
5
import compose from './compose'
6
+ import warning from './utils/warning'
6
7
7
8
/*
8
9
* This is a dummy function to check if the function name has been altered by minification.
@@ -11,15 +12,13 @@ import compose from './compose'
11
12
function isCrushed ( ) { }
12
13
13
14
if ( isCrushed . name !== 'isCrushed' && process . env . NODE_ENV !== 'production' ) {
14
- /*eslint-disable no-console */
15
- console . error (
16
- 'You are currently using minified code outside of NODE_ENV === \'production\'. ' +
17
- 'This means that you are running a slower development build of Redux. ' +
18
- 'You can use loose-envify (https://github.com/zertosh/loose-envify) for browserify ' +
19
- 'or DefinePlugin for webpack (http://stackoverflow.com/questions/30030031) ' +
15
+ warning (
16
+ 'You are currently using minified code outside of NODE_ENV === \'production\'. ' +
17
+ 'This means that you are running a slower development build of Redux. ' +
18
+ 'You can use loose-envify (https://github.com/zertosh/loose-envify) for browserify ' +
19
+ 'or DefinePlugin for webpack (http://stackoverflow.com/questions/30030031) ' +
20
20
'to ensure you have the correct code for your production build.'
21
- )
22
- /*eslint-enable */
21
+ )
23
22
}
24
23
25
24
export {
Original file line number Diff line number Diff line change
1
+ /**
2
+ * Prints a warning in the console if it exists.
3
+ *
4
+ * @param {String } message The warning message.
5
+ * @returns {void }
6
+ */
7
+ export default function warning ( message ) {
8
+ /* eslint-disable no-console */
9
+ if ( typeof console !== 'undefined' && typeof console . error === 'function' ) {
10
+ console . error ( message )
11
+ }
12
+ /* eslint-enable no-console */
13
+ try {
14
+ // This error was thrown as a convenience so that you can use this stack
15
+ // to find the callsite that caused this warning to fire.
16
+ throw new Error ( message )
17
+ /* eslint-disable no-empty */
18
+ } catch ( e ) { }
19
+ /* eslint-enable no-empty */
20
+ }
Original file line number Diff line number Diff line change
1
+ import expect from 'expect'
2
+ import warning from '../../src/utils/warning'
3
+
4
+ describe ( 'Utils' , ( ) => {
5
+ describe ( 'warning' , ( ) => {
6
+ it ( 'calls console.error when available' , ( ) => {
7
+ const spy = expect . spyOn ( console , 'error' )
8
+ try {
9
+ warning ( 'Test' )
10
+ expect ( spy . calls [ 0 ] . arguments [ 0 ] ) . toBe ( 'Test' )
11
+ } finally {
12
+ spy . restore ( )
13
+ }
14
+ } )
15
+
16
+ it ( 'does not throw when console.error is not available' , ( ) => {
17
+ const realConsole = global . console
18
+ Object . defineProperty ( global , 'console' , { value : { } } )
19
+ try {
20
+ expect ( ( ) => warning ( 'Test' ) ) . toNotThrow ( )
21
+ } finally {
22
+ Object . defineProperty ( global , 'console' , { value : realConsole } )
23
+ }
24
+ } )
25
+
26
+ it ( 'does not throw when console is not available' , ( ) => {
27
+ const realConsole = global . console
28
+ Object . defineProperty ( global , 'console' , { value : undefined } )
29
+ try {
30
+ expect ( ( ) => warning ( 'Test' ) ) . toNotThrow ( )
31
+ } finally {
32
+ Object . defineProperty ( global , 'console' , { value : realConsole } )
33
+ }
34
+ } )
35
+ } )
36
+ } )
You can’t perform that action at this time.
0 commit comments