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'
22import isPlainObject from './utils/isPlainObject'
33import mapValues from './utils/mapValues'
44import pick from './utils/pick'
5-
6- /* eslint-disable no-console */
5+ import warning from './utils/warning'
76
87function getUndefinedStateErrorMessage ( key , action ) {
98 var actionType = action && action . type
@@ -112,7 +111,7 @@ export default function combineReducers(reducers) {
112111 if ( process . env . NODE_ENV !== 'production' ) {
113112 var warningMessage = getUnexpectedStateShapeWarningMessage ( state , finalReducers , action )
114113 if ( warningMessage ) {
115- console . error ( warningMessage )
114+ warning ( warningMessage )
116115 }
117116 }
118117
Original file line number Diff line number Diff line change @@ -3,6 +3,7 @@ import combineReducers from './combineReducers'
33import bindActionCreators from './bindActionCreators'
44import applyMiddleware from './applyMiddleware'
55import compose from './compose'
6+ import warning from './utils/warning'
67
78/*
89* This is a dummy function to check if the function name has been altered by minification.
@@ -11,15 +12,13 @@ import compose from './compose'
1112function isCrushed ( ) { }
1213
1314if ( 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) ' +
2020 'to ensure you have the correct code for your production build.'
21- )
22- /*eslint-enable */
21+ )
2322}
2423
2524export {
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