132
}
133
134
ReactTestUtils.renderIntoDocument(<App />);
135
- expectDev(() => (style.position = 'absolute')).toThrow();
135
+ if (__DEV__) {
136
+ expect(() => (style.position = 'absolute')).toThrow();
137
+ }
138
});
139
140
it('should warn for unknown prop', () => {
139
- spyOn(console, 'error');
141
+ spyOnDev(console, 'error');
142
var container = document.createElement('div');
143
ReactDOM.render(<div foo={() => {}} />, container);
142
- expectDev(console.error.calls.count(0)).toBe(1);
143
- expectDev(normalizeCodeLocInfo(console.error.calls.argsFor(0)[0])).toBe(
144
- 'Warning: Invalid value for prop `foo` on <div> tag. Either remove it ' +
145
- 'from the element, or pass a string or number value to keep ' +
146
- 'it in the DOM. For details, see https://fb.me/react-attribute-behavior' +
147
- '\n in div (at **)',
148
- );
144
+ if (__DEV__) {
145
+ expect(console.error.calls.count(0)).toBe(1);
146
+ expect(normalizeCodeLocInfo(console.error.calls.argsFor(0)[0])).toBe(
147
+ 'Warning: Invalid value for prop `foo` on <div> tag. Either remove it ' +
148
+ 'from the element, or pass a string or number value to keep ' +
149
+ 'it in the DOM. For details, see https://fb.me/react-attribute-behavior' +
150
+ '\n in div (at **)',
151
+ );
152
+ }
153
});
154
155
it('should group multiple unknown prop warnings together', () => {
152
- spyOn(console, 'error');
156
+ spyOnDev(console, 'error');
157
var container = document.createElement('div');
158
ReactDOM.render(<div foo={() => {}} baz={() => {}} />, container);
155
- expectDev(console.error.calls.count(0)).toBe(1);
156
- expectDev(normalizeCodeLocInfo(console.error.calls.argsFor(0)[0])).toBe(
157
- 'Warning: Invalid values for props `foo`, `baz` on <div> tag. Either remove ' +
158
- 'them from the element, or pass a string or number value to keep ' +
159
- 'them in the DOM. For details, see https://fb.me/react-attribute-behavior' +
160
- '\n in div (at **)',
161
- );
159
+ if (__DEV__) {
160
+ expect(console.error.calls.count(0)).toBe(1);
161
+ expect(normalizeCodeLocInfo(console.error.calls.argsFor(0)[0])).toBe(
162
+ 'Warning: Invalid values for props `foo`, `baz` on <div> tag. Either remove ' +
163
+ 'them from the element, or pass a string or number value to keep ' +
164
+ 'them in the DOM. For details, see https://fb.me/react-attribute-behavior' +
165
+ '\n in div (at **)',
166
+ );
167
+ }
168
});
169
170
it('should warn for onDblClick prop', () => {
165
- spyOn(console, 'error');
171
+ spyOnDev(console, 'error');
172
var container = document.createElement('div');
173
ReactDOM.render(<div onDblClick={() => {}} />, container);
168
- expectDev(console.error.calls.count(0)).toBe(1);
169
- expectDev(normalizeCodeLocInfo(console.error.calls.argsFor(0)[0])).toBe(
170
- 'Warning: Invalid event handler property `onDblClick`. Did you mean `onDoubleClick`?\n in div (at **)',
171
- );
174
+ if (__DEV__) {
175
+ expect(console.error.calls.count(0)).toBe(1);
176
+ expect(normalizeCodeLocInfo(console.error.calls.argsFor(0)[0])).toBe(
177
+ 'Warning: Invalid event handler property `onDblClick`. Did you mean `onDoubleClick`?\n in div (at **)',
178
+ );
179
+ }
180
});
181
182
it('should warn for unknown string event handlers', () => {
175
- spyOn(console, 'error');
183
+ spyOnDev(console, 'error');
184
var container = document.createElement('div');
185
ReactDOM.render(<div onUnknown="alert("hack")" />, container);
186
expect(container.firstChild.hasAttribute('onUnknown')).toBe(false);
191
ReactDOM.render(<div on-unknown="alert("hack")" />, container);
192
expect(container.firstChild.hasAttribute('on-unknown')).toBe(false);
193
expect(container.firstChild['on-unknown']).toBe(undefined);
186
- expectDev(console.error.calls.count(0)).toBe(3);
187
- expectDev(normalizeCodeLocInfo(console.error.calls.argsFor(0)[0])).toBe(
188
- 'Warning: Unknown event handler property `onUnknown`. It will be ignored.\n in div (at **)',
189
- );
190
- expectDev(normalizeCodeLocInfo(console.error.calls.argsFor(1)[0])).toBe(
191
- 'Warning: Unknown event handler property `onunknown`. It will be ignored.\n in div (at **)',
192
- );
193
- expectDev(normalizeCodeLocInfo(console.error.calls.argsFor(2)[0])).toBe(
194
- 'Warning: Unknown event handler property `on-unknown`. It will be ignored.\n in div (at **)',
195
- );
194
+ if (__DEV__) {
195
+ expect(console.error.calls.count(0)).toBe(3);
196
+ expect(normalizeCodeLocInfo(console.error.calls.argsFor(0)[0])).toBe(
197
+ 'Warning: Unknown event handler property `onUnknown`. It will be ignored.\n in div (at **)',
198
+ );
199
+ expect(normalizeCodeLocInfo(console.error.calls.argsFor(1)[0])).toBe(
200
+ 'Warning: Unknown event handler property `onunknown`. It will be ignored.\n in div (at **)',
201
+ );
202
+ expect(normalizeCodeLocInfo(console.error.calls.argsFor(2)[0])).toBe(
203
+ 'Warning: Unknown event handler property `on-unknown`. It will be ignored.\n in div (at **)',
204
+ );
205
+ }
206
});
207
208
it('should warn for unknown function event handlers', () => {
199
- spyOn(console, 'error');
209
+ spyOnDev(console, 'error');
210
var container = document.createElement('div');
211
ReactDOM.render(<div onUnknown={function() {}} />, container);
212
expect(container.firstChild.hasAttribute('onUnknown')).toBe(false);
217
ReactDOM.render(<div on-unknown={function() {}} />, container);
218
expect(container.firstChild.hasAttribute('on-unknown')).toBe(false);
219
expect(container.firstChild['on-unknown']).toBe(undefined);
210
- expectDev(console.error.calls.count(0)).toBe(3);
211
- expectDev(normalizeCodeLocInfo(console.error.calls.argsFor(0)[0])).toBe(
212
- 'Warning: Unknown event handler property `onUnknown`. It will be ignored.\n in div (at **)',
213
- );
214
- expectDev(normalizeCodeLocInfo(console.error.calls.argsFor(1)[0])).toBe(
215
- 'Warning: Unknown event handler property `onunknown`. It will be ignored.\n in div (at **)',
216
- );
217
- expectDev(normalizeCodeLocInfo(console.error.calls.argsFor(2)[0])).toBe(
218
- 'Warning: Unknown event handler property `on-unknown`. It will be ignored.\n in div (at **)',
219
- );
220
+ if (__DEV__) {
221
+ expect(console.error.calls.count(0)).toBe(3);
222
+ expect(normalizeCodeLocInfo(console.error.calls.argsFor(0)[0])).toBe(
223
+ 'Warning: Unknown event handler property `onUnknown`. It will be ignored.\n in div (at **)',
224
+ );
225
+ expect(normalizeCodeLocInfo(console.error.calls.argsFor(1)[0])).toBe(
226
+ 'Warning: Unknown event handler property `onunknown`. It will be ignored.\n in div (at **)',
227
+ );
228
+ expect(normalizeCodeLocInfo(console.error.calls.argsFor(2)[0])).toBe(
229
+ 'Warning: Unknown event handler property `on-unknown`. It will be ignored.\n in div (at **)',
230
+ );
231
+ }
232
});
233
234
it('should warn for badly cased React attributes', () => {
223
- spyOn(console, 'error');
235
+ spyOnDev(console, 'error');
236
var container = document.createElement('div');
237
ReactDOM.render(<div CHILDREN="5" />, container);
238
expect(container.firstChild.getAttribute('CHILDREN')).toBe('5');
227
- expectDev(console.error.calls.count(0)).toBe(1);
228
- expectDev(normalizeCodeLocInfo(console.error.calls.argsFor(0)[0])).toBe(
229
- 'Warning: Invalid DOM property `CHILDREN`. Did you mean `children`?\n in div (at **)',
230
- );
239
+ if (__DEV__) {
240
+ expect(console.error.calls.count(0)).toBe(1);
241
+ expect(normalizeCodeLocInfo(console.error.calls.argsFor(0)[0])).toBe(
242
+ 'Warning: Invalid DOM property `CHILDREN`. Did you mean `children`?\n in div (at **)',
243
+ );
244
+ }
245
});
246
247
it('should not warn for "0" as a unitless style value', () => {
234
- spyOn(console, 'error');
235
-
248
class Component extends React.Component {
249
render() {
250
return <div style={{margin: '0'}} />;
252
}
253
254
ReactTestUtils.renderIntoDocument(<Component />);
243
- expectDev(console.error.calls.count()).toBe(0);
255
});
256
257
it('should warn nicely about NaN in style', () => {
247
- spyOn(console, 'error');
258
+ spyOnDev(console, 'error');
259
260
var style = {fontSize: NaN};
261
var div = document.createElement('div');
262
ReactDOM.render(<span style={style} />, div);
263
ReactDOM.render(<span style={style} />, div);
264
254
- expectDev(console.error.calls.count()).toBe(1);
255
- expectDev(
256
- normalizeCodeLocInfo(console.error.calls.argsFor(0)[0]),
257
- ).toEqual(
258
- 'Warning: `NaN` is an invalid value for the `fontSize` css style property.' +
259
- '\n in span (at **)',
260
- );
265
+ if (__DEV__) {
266
+ expect(console.error.calls.count()).toBe(1);
267
+ expect(normalizeCodeLocInfo(console.error.calls.argsFor(0)[0])).toEqual(
268
+ 'Warning: `NaN` is an invalid value for the `fontSize` css style property.' +
269
+ '\n in span (at **)',
270
+ );
271
+ }
272
});
273
274
it('should update styles if initially null', () => {
456
});
457
458
it('should reject attribute key injection attack on markup', () => {
448
- spyOn(console, 'error');
459
+ spyOnDev(console, 'error');
460
for (var i = 0; i < 3; i++) {
461
var container = document.createElement('div');
462
var element = React.createElement(
466
);
467
ReactDOM.render(element, container);
468
}
458
- expectDev(console.error.calls.count()).toBe(1);
459
- expectDev(console.error.calls.argsFor(0)[0]).toEqual(
460
- 'Warning: Invalid attribute name: `blah" onclick="beevil" noise="hi`',
461
- );
469
+ if (__DEV__) {
470
+ expect(console.error.calls.count()).toBe(1);
471
+ expect(console.error.calls.argsFor(0)[0]).toEqual(
472
+ 'Warning: Invalid attribute name: `blah" onclick="beevil" noise="hi`',
473
+ );
474
+ }
475
});
476
477
it('should reject attribute key injection attack on update', () => {
465
- spyOn(console, 'error');
478
+ spyOnDev(console, 'error');
479
for (var i = 0; i < 3; i++) {
480
var container = document.createElement('div');
481
var beforeUpdate = React.createElement('x-foo-component', {}, null);
488
);
489
ReactDOM.render(afterUpdate, container);
490
}
478
- expectDev(console.error.calls.count()).toBe(1);
479
- expectDev(console.error.calls.argsFor(0)[0]).toEqual(
480
- 'Warning: Invalid attribute name: `blah" onclick="beevil" noise="hi`',
481
- );
491
+ if (__DEV__) {
492
+ expect(console.error.calls.count()).toBe(1);
493
+ expect(console.error.calls.argsFor(0)[0]).toEqual(
494
+ 'Warning: Invalid attribute name: `blah" onclick="beevil" noise="hi`',
495
+ );
496
+ }
497
});
498
499
it('should update arbitrary attributes for tags containing dashes', () => {
738
});
739
740
it('should warn about non-string "is" attribute', () => {
726
- spyOn(console, 'error');
741
+ spyOnDev(console, 'error');
742
var container = document.createElement('div');
743
ReactDOM.render(<button is={function() {}} />, container);
744
730
- expectDev(console.error.calls.count()).toBe(1);
731
- expectDev(console.error.calls.argsFor(0)[0]).toContain(
732
- 'Received a `function` for a string attribute `is`. If this is expected, cast ' +
733
- 'the value to a string.',
734
- );
745
+ if (__DEV__) {
746
+ expect(console.error.calls.count()).toBe(1);
747
+ expect(console.error.calls.argsFor(0)[0]).toContain(
748
+ 'Received a `function` for a string attribute `is`. If this is expected, cast ' +
749
+ 'the value to a string.',
750
+ );
751
+ }
752
});
753
754
it('should not update when switching between null/undefined', () => {
877
});
878
879
it('should work error event on <source> element', () => {
863
- spyOn(console, 'error');
880
+ spyOn(console, 'log');
881
var container = document.createElement('div');
882
ReactDOM.render(
883
<video>
884
<source
885
src="http://example.org/video"
886
type="video/mp4"
870
- onError={e => console.error('onError called')}
887
+ onError={e => console.log('onError called')}
888
/>
889
</video>,
890
container,
894
errorEvent.initEvent('error', false, false);
895
container.getElementsByTagName('source')[0].dispatchEvent(errorEvent);
896
880
- expectDev(console.error.calls.count()).toBe(1);
881
- expectDev(console.error.calls.argsFor(0)[0]).toContain('onError called');
897
+ if (__DEV__) {
898
+ expect(console.log.calls.count()).toBe(1);
899
+ expect(console.log.calls.argsFor(0)[0]).toContain('onError called');
900
+ }
901
});
902
903
it('should not duplicate uppercased selfclosing tags', () => {
885
- spyOn(console, 'error');
904
+ spyOnDev(console, 'error');
905
class Container extends React.Component {
906
render() {
907
return React.createElement('BR', null);
910
911
var returnedValue = ReactDOMServer.renderToString(<Container />);
912
expect(returnedValue).not.toContain('</BR>');
894
- expectDev(console.error.calls.count()).toBe(1);
895
- expectDev(console.error.calls.argsFor(0)[0]).toContain(
896
- '<BR /> is using uppercase HTML.',
897
- );
913
+ if (__DEV__) {
914
+ expect(console.error.calls.count()).toBe(1);
915
+ expect(console.error.calls.argsFor(0)[0]).toContain(
916
+ '<BR /> is using uppercase HTML.',
917
+ );
918
+ }
919
});
920
921
it('should warn on upper case HTML tags, not SVG nor custom tags', () => {
901
- spyOn(console, 'error');
922
+ spyOnDev(console, 'error');
923
ReactTestUtils.renderIntoDocument(
924
React.createElement('svg', null, React.createElement('PATH')),
925
);
905
- expectDev(console.error.calls.count()).toBe(0);
926
+ if (__DEV__) {
927
+ expect(console.error.calls.count()).toBe(0);
928
+ }
929
ReactTestUtils.renderIntoDocument(React.createElement('CUSTOM-TAG'));
907
- expectDev(console.error.calls.count()).toBe(0);
930
+ if (__DEV__) {
931
+ expect(console.error.calls.count()).toBe(0);
932
+ }
933
ReactTestUtils.renderIntoDocument(React.createElement('IMG'));
909
- expectDev(console.error.calls.count()).toBe(1);
910
- expectDev(console.error.calls.argsFor(0)[0]).toContain(
911
- '<IMG /> is using uppercase HTML.',
912
- );
934
+ if (__DEV__) {
935
+ expect(console.error.calls.count()).toBe(1);
936
+ expect(console.error.calls.argsFor(0)[0]).toContain(
937
+ '<IMG /> is using uppercase HTML.',
938
+ );
939
+ }
940
});
941
942
it('should warn on props reserved for future use', () => {
916
- spyOn(console, 'error');
943
+ spyOnDev(console, 'error');
944
ReactTestUtils.renderIntoDocument(<div aria="hello" />);
918
- expectDev(console.error.calls.count()).toBe(1);
919
- expectDev(console.error.calls.argsFor(0)[0]).toContain(
920
- 'The `aria` attribute is reserved for future use in React. ' +
921
- 'Pass individual `aria-` attributes instead.',
922
- );
945
+ if (__DEV__) {
946
+ expect(console.error.calls.count()).toBe(1);
947
+ expect(console.error.calls.argsFor(0)[0]).toContain(
948
+ 'The `aria` attribute is reserved for future use in React. ' +
949
+ 'Pass individual `aria-` attributes instead.',
950
+ );
951
+ }
952
});
953
954
it('should warn if the tag is unrecognized', () => {
926
- spyOn(console, 'error');
955
+ spyOnDev(console, 'error');
956
957
let realToString;
958
try {
986
Object.prototype.toString = realToString; // eslint-disable-line no-extend-native
987
}
988
960
- expectDev(console.error.calls.count()).toBe(4);
961
- expectDev(console.error.calls.argsFor(0)[0]).toContain(
962
- 'The tag <bar> is unrecognized in this browser',
963
- );
964
- expectDev(console.error.calls.argsFor(1)[0]).toContain(
965
- 'The tag <foo> is unrecognized in this browser',
966
- );
967
- expectDev(console.error.calls.argsFor(2)[0]).toContain(
968
- '<hasOwnProperty /> is using uppercase HTML',
969
- );
970
- expectDev(console.error.calls.argsFor(3)[0]).toContain(
971
- 'The tag <hasOwnProperty> is unrecognized in this browser',
972
- );
989
+ if (__DEV__) {
990
+ expect(console.error.calls.count()).toBe(4);
991
+ expect(console.error.calls.argsFor(0)[0]).toContain(
992
+ 'The tag <bar> is unrecognized in this browser',
993
+ );
994
+ expect(console.error.calls.argsFor(1)[0]).toContain(
995
+ 'The tag <foo> is unrecognized in this browser',
996
+ );
997
+ expect(console.error.calls.argsFor(2)[0]).toContain(
998
+ '<hasOwnProperty /> is using uppercase HTML',
999
+ );
1000
+ expect(console.error.calls.argsFor(3)[0]).toContain(
1001
+ 'The tag <hasOwnProperty> is unrecognized in this browser',
1002
+ );
1003
+ }
1004
});
1005
1006
it('should throw on children for void elements', () => {
1014
expect(caughtErr).not.toBe(undefined);
1015
expect(normalizeCodeLocInfo(caughtErr.message)).toContain(
1016
'input is a void element tag and must neither have `children` nor ' +
986
- 'use `dangerouslySetInnerHTML`.',
987
- '\n in input (at **)',
1017
+ 'use `dangerouslySetInnerHTML`.' +
1018
+ (__DEV__ ? '\n in input (at **)' : ''),
1019
);
1020
});
1021
1033
expect(caughtErr).not.toBe(undefined);
1034
expect(normalizeCodeLocInfo(caughtErr.message)).toContain(
1035
'input is a void element tag and must neither have `children` nor ' +
1005
- 'use `dangerouslySetInnerHTML`.',
1006
- '\n in input (at **)',
1036
+ 'use `dangerouslySetInnerHTML`.' +
1037
+ (__DEV__ ? '\n in input (at **)' : ''),
1038
);
1039
});
1040
1041
it('should emit a warning once for a named custom component using shady DOM', () => {
1011
- spyOn(console, 'error');
1042
+ spyOnDev(console, 'error');
1043
1044
var defaultCreateElement = document.createElement.bind(document);
1045
1056
}
1057
var node = document.createElement('div');
1058
ReactDOM.render(<ShadyComponent />, node);
1028
- expectDev(console.error.calls.count()).toBe(1);
1029
- expectDev(console.error.calls.argsFor(0)[0]).toContain(
1030
- 'ShadyComponent is using shady DOM. Using shady DOM with React can ' +
1031
- 'cause things to break subtly.',
1032
- );
1059
+ if (__DEV__) {
1060
+ expect(console.error.calls.count()).toBe(1);
1061
+ expect(console.error.calls.argsFor(0)[0]).toContain(
1062
+ 'ShadyComponent is using shady DOM. Using shady DOM with React can ' +
1063
+ 'cause things to break subtly.',
1064
+ );
1065
+ }
1066
mountComponent({is: 'custom-shady-div2'});
1034
- expectDev(console.error.calls.count()).toBe(1);
1067
+ if (__DEV__) {
1068
+ expect(console.error.calls.count()).toBe(1);
1069
+ }
1070
} finally {
1071
document.createElement = defaultCreateElement;
1072
}
1073
});
1074
1075
it('should emit a warning once for an unnamed custom component using shady DOM', () => {
1041
- spyOn(console, 'error');
1076
+ spyOnDev(console, 'error');
1077
1078
var defaultCreateElement = document.createElement.bind(document);
1079
1085
};
1086
1087
mountComponent({is: 'custom-shady-div'});
1053
- expectDev(console.error.calls.count()).toBe(1);
1054
- expectDev(console.error.calls.argsFor(0)[0]).toContain(
1055
- 'A component is using shady DOM. Using shady DOM with React can ' +
1056
- 'cause things to break subtly.',
1057
- );
1088
+ if (__DEV__) {
1089
+ expect(console.error.calls.count()).toBe(1);
1090
+ expect(console.error.calls.argsFor(0)[0]).toContain(
1091
+ 'A component is using shady DOM. Using shady DOM with React can ' +
1092
+ 'cause things to break subtly.',
1093
+ );
1094
+ }
1095
1096
mountComponent({is: 'custom-shady-div2'});
1060
- expectDev(console.error.calls.count()).toBe(1);
1097
+ if (__DEV__) {
1098
+ expect(console.error.calls.count()).toBe(1);
1099
+ }
1100
} finally {
1101
document.createElement = defaultCreateElement;
1102
}
1104
1105
it('should treat menuitem as a void element but still create the closing tag', () => {
1106
// menuitem is not implemented in jsdom, so this triggers the unknown warning error
1068
- spyOn(console, 'error');
1107
+ spyOnDev(console, 'error');
1108
var container = document.createElement('div');
1109
1110
var returnedValue = ReactDOMServer.renderToString(
1137
});
1138
1139
it('should validate against use of innerHTML', () => {
1101
- spyOn(console, 'error');
1140
+ spyOnDev(console, 'error');
1141
mountComponent({innerHTML: '<span>Hi Jim!</span>'});
1103
- expectDev(console.error.calls.count()).toBe(1);
1104
- expectDev(console.error.calls.argsFor(0)[0]).toContain(
1105
- 'Directly setting property `innerHTML` is not permitted. ',
1106
- );
1142
+ if (__DEV__) {
1143
+ expect(console.error.calls.count()).toBe(1);
1144
+ expect(console.error.calls.argsFor(0)[0]).toContain(
1145
+ 'Directly setting property `innerHTML` is not permitted. ',
1146
+ );
1147
+ }
1148
});
1149
1150
it('should validate against use of innerHTML without case sensitivity', () => {
1110
- spyOn(console, 'error');
1151
+ spyOnDev(console, 'error');
1152
mountComponent({innerhtml: '<span>Hi Jim!</span>'});
1112
- expectDev(console.error.calls.count()).toBe(1);
1113
- expectDev(console.error.calls.argsFor(0)[0]).toContain(
1114
- 'Directly setting property `innerHTML` is not permitted. ',
1115
- );
1153
+ if (__DEV__) {
1154
+ expect(console.error.calls.count()).toBe(1);
1155
+ expect(console.error.calls.argsFor(0)[0]).toContain(
1156
+ 'Directly setting property `innerHTML` is not permitted. ',
1157
+ );
1158
+ }
1159
});
1160
1161
it('should validate use of dangerouslySetInnerHTML', () => {
1183
});
1184
1185
it('should warn about contentEditable and children', () => {
1143
- spyOn(console, 'error');
1186
+ spyOnDev(console, 'error');
1187
mountComponent({contentEditable: true, children: ''});
1145
- expectDev(console.error.calls.count()).toBe(1);
1146
- expectDev(normalizeCodeLocInfo(console.error.calls.argsFor(0)[0])).toBe(
1147
- 'Warning: A component is `contentEditable` and contains `children` ' +
1148
- 'managed by React. It is now your responsibility to guarantee that ' +
1149
- 'none of those nodes are unexpectedly modified or duplicated. This ' +
1150
- 'is probably not intentional.\n in div (at **)',
1151
- );
1188
+ if (__DEV__) {
1189
+ expect(console.error.calls.count()).toBe(1);
1190
+ expect(normalizeCodeLocInfo(console.error.calls.argsFor(0)[0])).toBe(
1191
+ 'Warning: A component is `contentEditable` and contains `children` ' +
1192
+ 'managed by React. It is now your responsibility to guarantee that ' +
1193
+ 'none of those nodes are unexpectedly modified or duplicated. This ' +
1194
+ 'is probably not intentional.\n in div (at **)',
1195
+ );
1196
+ }
1197
});
1198
1199
it('should respect suppressContentEditableWarning', () => {
1155
- spyOn(console, 'error');
1200
mountComponent({
1201
contentEditable: true,
1202
children: '',
1203
suppressContentEditableWarning: true,
1204
});
1161
- expectDev(console.error.calls.count()).toBe(0);
1205
});
1206
1207
it('should validate against invalid styles', () => {
1233
expect(normalizeCodeLocInfo(caughtErr.message)).toContain(
1234
'input is a void element tag and must neither have `children` ' +
1235
'nor use `dangerouslySetInnerHTML`.' +
1193
- '\n in input (at **)' +
1194
- '\n in X (at **)',
1236
+ (__DEV__ ? '\n in input (at **)' + '\n in X (at **)' : ''),
1237
);
1238
});
1239
1269
container.getElementsByTagName('image')[0].dispatchEvent(errorEvent);
1270
container.getElementsByTagName('image')[0].dispatchEvent(loadEvent);
1271
1230
- expectDev(console.log.calls.count()).toBe(2);
1231
- expectDev(console.log.calls.argsFor(0)[0]).toContain('onError called');
1232
- expectDev(console.log.calls.argsFor(1)[0]).toContain('onLoad called');
1272
+ if (__DEV__) {
1273
+ expect(console.log.calls.count()).toBe(2);
1274
+ expect(console.log.calls.argsFor(0)[0]).toContain('onError called');
1275
+ expect(console.log.calls.argsFor(1)[0]).toContain('onLoad called');
1276
+ }
1277
});
1278
});
1279
1323
});
1324
1325
it('should warn about contentEditable and children', () => {
1282
- spyOn(console, 'error');
1326
+ spyOnDev(console, 'error');
1327
ReactDOM.render(
1328
<div contentEditable={true}>
1329
<div />
1330
</div>,
1331
container,
1332
);
1289
- expectDev(console.error.calls.count()).toBe(1);
1290
- expectDev(console.error.calls.argsFor(0)[0]).toContain('contentEditable');
1333
+ if (__DEV__) {
1334
+ expect(console.error.calls.count()).toBe(1);
1335
+ expect(console.error.calls.argsFor(0)[0]).toContain('contentEditable');
1336
+ }
1337
});
1338
1339
it('should validate against invalid styles', () => {
1367
'The `style` prop expects a mapping from style properties to values, ' +
1368
"not a string. For example, style={{marginRight: spacing + 'em'}} " +
1369
'when using JSX.' +
1324
- '\n in div (at **)' +
1325
- '\n in Animal (at **)',
1370
+ (__DEV__ ? '\n in div (at **)' + '\n in Animal (at **)' : ''),
1371
);
1372
});
1373
1445
1446
describe('nesting validation', () => {
1447
it('warns on invalid nesting', () => {
1403
- spyOn(console, 'error');
1448
+ spyOnDev(console, 'error');
1449
ReactTestUtils.renderIntoDocument(
1450
<div>
1451
<tr />
1453
</div>,
1454
);
1455
1411
- expectDev(console.error.calls.count()).toBe(2);
1412
- expectDev(normalizeCodeLocInfo(console.error.calls.argsFor(0)[0])).toBe(
1413
- 'Warning: validateDOMNesting(...): <tr> cannot appear as a child of ' +
1414
- '<div>.' +
1415
- '\n in tr (at **)' +
1416
- '\n in div (at **)',
1417
- );
1418
- expectDev(normalizeCodeLocInfo(console.error.calls.argsFor(1)[0])).toBe(
1419
- 'Warning: validateDOMNesting(...): <tr> cannot appear as a child of ' +
1420
- '<div>.' +
1421
- '\n in tr (at **)' +
1422
- '\n in div (at **)',
1423
- );
1456
+ if (__DEV__) {
1457
+ expect(console.error.calls.count()).toBe(2);
1458
+ expect(normalizeCodeLocInfo(console.error.calls.argsFor(0)[0])).toBe(
1459
+ 'Warning: validateDOMNesting(...): <tr> cannot appear as a child of ' +
1460
+ '<div>.' +
1461
+ '\n in tr (at **)' +
1462
+ '\n in div (at **)',
1463
+ );
1464
+ expect(normalizeCodeLocInfo(console.error.calls.argsFor(1)[0])).toBe(
1465
+ 'Warning: validateDOMNesting(...): <tr> cannot appear as a child of ' +
1466
+ '<div>.' +
1467
+ '\n in tr (at **)' +
1468
+ '\n in div (at **)',
1469
+ );
1470
+ }
1471
});
1472
1473
it('warns on invalid nesting at root', () => {
1427
- spyOn(console, 'error');
1474
+ spyOnDev(console, 'error');
1475
var p = document.createElement('p');
1476
ReactDOM.render(
1477
<span>
1480
p,
1481
);
1482
1436
- expectDev(console.error.calls.count()).toBe(1);
1437
- expectDev(normalizeCodeLocInfo(console.error.calls.argsFor(0)[0])).toBe(
1438
- 'Warning: validateDOMNesting(...): <p> cannot appear as a descendant ' +
1439
- 'of <p>.' +
1440
- // There is no outer `p` here because root container is not part of the stack.
1441
- '\n in p (at **)' +
1442
- '\n in span (at **)',
1443
- );
1483
+ if (__DEV__) {
1484
+ expect(console.error.calls.count()).toBe(1);
1485
+ expect(normalizeCodeLocInfo(console.error.calls.argsFor(0)[0])).toBe(
1486
+ 'Warning: validateDOMNesting(...): <p> cannot appear as a descendant ' +
1487
+ 'of <p>.' +
1488
+ // There is no outer `p` here because root container is not part of the stack.
1489
+ '\n in p (at **)' +
1490
+ '\n in span (at **)',
1491
+ );
1492
+ }
1493
});
1494
1495
it('warns nicely for table rows', () => {
1447
- spyOn(console, 'error');
1496
+ spyOnDev(console, 'error');
1497
1498
class Row extends React.Component {
1499
render() {
1512
}
1513
1514
ReactTestUtils.renderIntoDocument(<Foo />);
1466
- expectDev(console.error.calls.count()).toBe(3);
1467
-
1468
- expectDev(normalizeCodeLocInfo(console.error.calls.argsFor(0)[0])).toBe(
1469
- 'Warning: validateDOMNesting(...): <tr> cannot appear as a child of ' +
1470
- '<table>. Add a <tbody> to your code to match the DOM tree generated ' +
1471
- 'by the browser.' +
1472
- '\n in tr (at **)' +
1473
- '\n in Row (at **)' +
1474
- '\n in table (at **)' +
1475
- '\n in Foo (at **)',
1476
- );
1515
+ if (__DEV__) {
1516
+ expect(console.error.calls.count()).toBe(3);
1517
+
1518
+ expect(normalizeCodeLocInfo(console.error.calls.argsFor(0)[0])).toBe(
1519
+ 'Warning: validateDOMNesting(...): <tr> cannot appear as a child of ' +
1520
+ '<table>. Add a <tbody> to your code to match the DOM tree generated ' +
1521
+ 'by the browser.' +
1522
+ '\n in tr (at **)' +
1523
+ '\n in Row (at **)' +
1524
+ '\n in table (at **)' +
1525
+ '\n in Foo (at **)',
1526
+ );
1527
1478
- expectDev(normalizeCodeLocInfo(console.error.calls.argsFor(1)[0])).toBe(
1479
- 'Warning: validateDOMNesting(...): Text nodes cannot appear as a ' +
1480
- 'child of <tr>.' +
1481
- '\n in tr (at **)' +
1482
- '\n in Row (at **)' +
1483
- '\n in table (at **)' +
1484
- '\n in Foo (at **)',
1485
- );
1528
+ expect(normalizeCodeLocInfo(console.error.calls.argsFor(1)[0])).toBe(
1529
+ 'Warning: validateDOMNesting(...): Text nodes cannot appear as a ' +
1530
+ 'child of <tr>.' +
1531
+ '\n in tr (at **)' +
1532
+ '\n in Row (at **)' +
1533
+ '\n in table (at **)' +
1534
+ '\n in Foo (at **)',
1535
+ );
1536
1487
- expectDev(normalizeCodeLocInfo(console.error.calls.argsFor(2)[0])).toBe(
1488
- 'Warning: validateDOMNesting(...): Whitespace text nodes cannot ' +
1489
- "appear as a child of <table>. Make sure you don't have any extra " +
1490
- 'whitespace between tags on each line of your source code.' +
1491
- '\n in table (at **)' +
1492
- '\n in Foo (at **)',
1493
- );
1537
+ expect(normalizeCodeLocInfo(console.error.calls.argsFor(2)[0])).toBe(
1538
+ 'Warning: validateDOMNesting(...): Whitespace text nodes cannot ' +
1539
+ "appear as a child of <table>. Make sure you don't have any extra " +
1540
+ 'whitespace between tags on each line of your source code.' +
1541
+ '\n in table (at **)' +
1542
+ '\n in Foo (at **)',
1543
+ );
1544
+ }
1545
});
1546
1547
it('gives useful context in warnings', () => {
1497
- spyOn(console, 'error');
1548
+ spyOnDev(console, 'error');
1549
function Row() {
1550
return <tr />;
1551
}
1576
return <Viz1 />;
1577
}
1578
ReactTestUtils.renderIntoDocument(<App1 />);
1528
- expectDev(console.error.calls.count()).toBe(1);
1529
- expectDev(
1530
- normalizeCodeLocInfo(console.error.calls.argsFor(0)[0]),
1531
- ).toContain(
1532
- '\n in tr (at **)' +
1533
- '\n in Row (at **)' +
1534
- '\n in FancyRow (at **)' +
1535
- '\n in table (at **)' +
1536
- '\n in Viz1 (at **)',
1537
- );
1579
+ if (__DEV__) {
1580
+ expect(console.error.calls.count()).toBe(1);
1581
+ expect(
1582
+ normalizeCodeLocInfo(console.error.calls.argsFor(0)[0]),
1583
+ ).toContain(
1584
+ '\n in tr (at **)' +
1585
+ '\n in Row (at **)' +
1586
+ '\n in FancyRow (at **)' +
1587
+ '\n in table (at **)' +
1588
+ '\n in Viz1 (at **)',
1589
+ );
1590
+ }
1591
1592
function Viz2() {
1593
return (
1600
return <Viz2 />;
1601
}
1602
ReactTestUtils.renderIntoDocument(<App2 />);
1550
- expectDev(console.error.calls.count()).toBe(2);
1551
- expectDev(
1552
- normalizeCodeLocInfo(console.error.calls.argsFor(1)[0]),
1553
- ).toContain(
1554
- '\n in tr (at **)' +
1555
- '\n in Row (at **)' +
1556
- '\n in FancyRow (at **)' +
1557
- '\n in table (at **)' +
1558
- '\n in Table (at **)' +
1559
- '\n in FancyTable (at **)' +
1560
- '\n in Viz2 (at **)',
1561
- );
1603
+ if (__DEV__) {
1604
+ expect(console.error.calls.count()).toBe(2);
1605
+ expect(
1606
+ normalizeCodeLocInfo(console.error.calls.argsFor(1)[0]),
1607
+ ).toContain(
1608
+ '\n in tr (at **)' +
1609
+ '\n in Row (at **)' +
1610
+ '\n in FancyRow (at **)' +
1611
+ '\n in table (at **)' +
1612
+ '\n in Table (at **)' +
1613
+ '\n in FancyTable (at **)' +
1614
+ '\n in Viz2 (at **)',
1615
+ );
1616
+ }
1617
1618
ReactTestUtils.renderIntoDocument(
1619
<FancyTable>
1620
<FancyRow />
1621
</FancyTable>,
1622
);
1568
- expectDev(console.error.calls.count()).toBe(3);
1569
- expectDev(
1570
- normalizeCodeLocInfo(console.error.calls.argsFor(2)[0]),
1571
- ).toContain(
1572
- '\n in tr (at **)' +
1573
- '\n in Row (at **)' +
1574
- '\n in FancyRow (at **)' +
1575
- '\n in table (at **)' +
1576
- '\n in Table (at **)' +
1577
- '\n in FancyTable (at **)',
1578
- );
1623
+ if (__DEV__) {
1624
+ expect(console.error.calls.count()).toBe(3);
1625
+ expect(
1626
+ normalizeCodeLocInfo(console.error.calls.argsFor(2)[0]),
1627
+ ).toContain(
1628
+ '\n in tr (at **)' +
1629
+ '\n in Row (at **)' +
1630
+ '\n in FancyRow (at **)' +
1631
+ '\n in table (at **)' +
1632
+ '\n in Table (at **)' +
1633
+ '\n in FancyTable (at **)',
1634
+ );
1635
+ }
1636
1637
ReactTestUtils.renderIntoDocument(
1638
<table>
1639
<FancyRow />
1640
</table>,
1641
);
1585
- expectDev(console.error.calls.count()).toBe(4);
1586
- expectDev(
1587
- normalizeCodeLocInfo(console.error.calls.argsFor(3)[0]),
1588
- ).toContain(
1589
- '\n in tr (at **)' +
1590
- '\n in Row (at **)' +
1591
- '\n in FancyRow (at **)' +
1592
- '\n in table (at **)',
1593
- );
1642
+ if (__DEV__) {
1643
+ expect(console.error.calls.count()).toBe(4);
1644
+ expect(
1645
+ normalizeCodeLocInfo(console.error.calls.argsFor(3)[0]),
1646
+ ).toContain(
1647
+ '\n in tr (at **)' +
1648
+ '\n in Row (at **)' +
1649
+ '\n in FancyRow (at **)' +
1650
+ '\n in table (at **)',
1651
+ );
1652
+ }
1653
1654
ReactTestUtils.renderIntoDocument(
1655
<FancyTable>
1656
<tr />
1657
</FancyTable>,
1658
);
1600
- expectDev(console.error.calls.count()).toBe(5);
1601
- expectDev(
1602
- normalizeCodeLocInfo(console.error.calls.argsFor(4)[0]),
1603
- ).toContain(
1604
- '\n in tr (at **)' +
1605
- '\n in table (at **)' +
1606
- '\n in Table (at **)' +
1607
- '\n in FancyTable (at **)',
1608
- );
1659
+ if (__DEV__) {
1660
+ expect(console.error.calls.count()).toBe(5);
1661
+ expect(
1662
+ normalizeCodeLocInfo(console.error.calls.argsFor(4)[0]),
1663
+ ).toContain(
1664
+ '\n in tr (at **)' +
1665
+ '\n in table (at **)' +
1666
+ '\n in Table (at **)' +
1667
+ '\n in FancyTable (at **)',
1668
+ );
1669
+ }
1670
1671
class Link extends React.Component {
1672
render() {
1681
</div>
1682
</Link>,
1683
);
1623
- expectDev(console.error.calls.count()).toBe(6);
1624
- expectDev(
1625
- normalizeCodeLocInfo(console.error.calls.argsFor(5)[0]),
1626
- ).toContain(
1627
- '\n in a (at **)' +
1628
- '\n in Link (at **)' +
1629
- '\n in div (at **)' +
1684
+ if (__DEV__) {
1685
+ expect(console.error.calls.count()).toBe(6);
1686
+ expect(
1687
+ normalizeCodeLocInfo(console.error.calls.argsFor(5)[0]),
1688
+ ).toContain(
1689
'\n in a (at **)' +
1631
- '\n in Link (at **)',
1632
- );
1690
+ '\n in Link (at **)' +
1691
+ '\n in div (at **)' +
1692
+ '\n in a (at **)' +
1693
+ '\n in Link (at **)',
1694
+ );
1695
+ }
1696
});
1697
1698
it('should warn about incorrect casing on properties (ssr)', () => {
1636
- spyOn(console, 'error');
1699
+ spyOnDev(console, 'error');
1700
ReactDOMServer.renderToString(
1701
React.createElement('input', {type: 'text', tabindex: '1'}),
1702
);
1640
- expectDev(console.error.calls.count()).toBe(1);
1641
- expectDev(console.error.calls.argsFor(0)[0]).toContain('tabIndex');
1703
+ if (__DEV__) {
1704
+ expect(console.error.calls.count()).toBe(1);
1705
+ expect(console.error.calls.argsFor(0)[0]).toContain('tabIndex');
1706
+ }
1707
});
1708
1709
it('should warn about incorrect casing on event handlers (ssr)', () => {
1645
- spyOn(console, 'error');
1710
+ spyOnDev(console, 'error');
1711
ReactDOMServer.renderToString(
1712
React.createElement('input', {type: 'text', onclick: '1'}),
1713
);
1714
ReactDOMServer.renderToString(
1715
React.createElement('input', {type: 'text', onKeydown: '1'}),
1716
);
1652
- expectDev(console.error.calls.count()).toBe(2);
1653
- expectDev(console.error.calls.argsFor(0)[0]).toContain('onClick');
1654
- expectDev(console.error.calls.argsFor(1)[0]).toContain('onKeyDown');
1717
+ if (__DEV__) {
1718
+ expect(console.error.calls.count()).toBe(2);
1719
+ expect(console.error.calls.argsFor(0)[0]).toContain('onClick');
1720
+ expect(console.error.calls.argsFor(1)[0]).toContain('onKeyDown');
1721
+ }
1722
});
1723
1724
it('should warn about incorrect casing on properties', () => {
1658
- spyOn(console, 'error');
1725
+ spyOnDev(console, 'error');
1726
ReactTestUtils.renderIntoDocument(
1727
React.createElement('input', {type: 'text', tabindex: '1'}),
1728
);
1662
- expectDev(console.error.calls.count()).toBe(1);
1663
- expectDev(console.error.calls.argsFor(0)[0]).toContain('tabIndex');
1729
+ if (__DEV__) {
1730
+ expect(console.error.calls.count()).toBe(1);
1731
+ expect(console.error.calls.argsFor(0)[0]).toContain('tabIndex');
1732
+ }
1733
});
1734
1735
it('should warn about incorrect casing on event handlers', () => {
1667
- spyOn(console, 'error');
1736
+ spyOnDev(console, 'error');
1737
ReactTestUtils.renderIntoDocument(
1738
React.createElement('input', {type: 'text', onclick: '1'}),
1739
);
1740
ReactTestUtils.renderIntoDocument(
1741
React.createElement('input', {type: 'text', onKeydown: '1'}),
1742
);
1674
- expectDev(console.error.calls.count()).toBe(2);
1675
- expectDev(console.error.calls.argsFor(0)[0]).toContain('onClick');
1676
- expectDev(console.error.calls.argsFor(1)[0]).toContain('onKeyDown');
1743
+ if (__DEV__) {
1744
+ expect(console.error.calls.count()).toBe(2);
1745
+ expect(console.error.calls.argsFor(0)[0]).toContain('onClick');
1746
+ expect(console.error.calls.argsFor(1)[0]).toContain('onKeyDown');
1747
+ }
1748
});
1749
1750
it('should warn about class', () => {
1680
- spyOn(console, 'error');
1751
+ spyOnDev(console, 'error');
1752
ReactTestUtils.renderIntoDocument(
1753
React.createElement('div', {class: 'muffins'}),
1754
);
1684
- expectDev(console.error.calls.count()).toBe(1);
1685
- expectDev(console.error.calls.argsFor(0)[0]).toContain('className');
1755
+ if (__DEV__) {
1756
+ expect(console.error.calls.count()).toBe(1);
1757
+ expect(console.error.calls.argsFor(0)[0]).toContain('className');
1758
+ }
1759
});
1760
1761
it('should warn about class (ssr)', () => {
1689
- spyOn(console, 'error');
1762
+ spyOnDev(console, 'error');
1763
ReactDOMServer.renderToString(
1764
React.createElement('div', {class: 'muffins'}),
1765
);
1693
- expectDev(console.error.calls.count()).toBe(1);
1694
- expectDev(console.error.calls.argsFor(0)[0]).toContain('className');
1766
+ if (__DEV__) {
1767
+ expect(console.error.calls.count()).toBe(1);
1768
+ expect(console.error.calls.argsFor(0)[0]).toContain('className');
1769
+ }
1770
});
1771
1772
it('should warn about props that are no longer supported', () => {
1698
- spyOn(console, 'error');
1773
+ spyOnDev(console, 'error');
1774
ReactTestUtils.renderIntoDocument(<div />);
1700
- expectDev(console.error.calls.count()).toBe(0);
1775
+ if (__DEV__) {
1776
+ expect(console.error.calls.count()).toBe(0);
1777
+ }
1778
1779
ReactTestUtils.renderIntoDocument(<div onFocusIn={() => {}} />);
1703
- expectDev(console.error.calls.count()).toBe(1);
1780
+ if (__DEV__) {
1781
+ expect(console.error.calls.count()).toBe(1);
1782
+ }
1783
1784
ReactTestUtils.renderIntoDocument(<div onFocusOut={() => {}} />);
1706
- expectDev(console.error.calls.count()).toBe(2);
1785
+ if (__DEV__) {
1786
+ expect(console.error.calls.count()).toBe(2);
1787
+ }
1788
});
1789
1790
it('should warn about props that are no longer supported without case sensitivity', () => {
1710
- spyOn(console, 'error');
1791
+ spyOnDev(console, 'error');
1792
ReactTestUtils.renderIntoDocument(<div />);
1712
- expectDev(console.error.calls.count()).toBe(0);
1793
+ if (__DEV__) {
1794
+ expect(console.error.calls.count()).toBe(0);
1795
+ }
1796
1797
ReactTestUtils.renderIntoDocument(<div onfocusin={() => {}} />);
1715
- expectDev(console.error.calls.count()).toBe(1);
1798
+ if (__DEV__) {
1799
+ expect(console.error.calls.count()).toBe(1);
1800
+ }
1801
1802
ReactTestUtils.renderIntoDocument(<div onfocusout={() => {}} />);
1718
- expectDev(console.error.calls.count()).toBe(2);
1803
+ if (__DEV__) {
1804
+ expect(console.error.calls.count()).toBe(2);
1805
+ }
1806
});
1807
1808
it('should warn about props that are no longer supported (ssr)', () => {
1722
- spyOn(console, 'error');
1809
+ spyOnDev(console, 'error');
1810
ReactDOMServer.renderToString(<div />);
1724
- expectDev(console.error.calls.count()).toBe(0);
1811
+ if (__DEV__) {
1812
+ expect(console.error.calls.count()).toBe(0);
1813
+ }
1814
1815
ReactDOMServer.renderToString(<div onFocusIn={() => {}} />);
1727
- expectDev(console.error.calls.count()).toBe(1);
1816
+ if (__DEV__) {
1817
+ expect(console.error.calls.count()).toBe(1);
1818
+ }
1819
1820
ReactDOMServer.renderToString(<div onFocusOut={() => {}} />);
1730
- expectDev(console.error.calls.count()).toBe(2);
1821
+ if (__DEV__) {
1822
+ expect(console.error.calls.count()).toBe(2);
1823
+ }
1824
});
1825
1826
it('should warn about props that are no longer supported without case sensitivity (ssr)', () => {
1734
- spyOn(console, 'error');
1827
+ spyOnDev(console, 'error');
1828
ReactDOMServer.renderToString(<div />);
1736
- expectDev(console.error.calls.count()).toBe(0);
1829
+ if (__DEV__) {
1830
+ expect(console.error.calls.count()).toBe(0);
1831
+ }
1832
1833
ReactDOMServer.renderToString(<div onfocusin={() => {}} />);
1739
- expectDev(console.error.calls.count()).toBe(1);
1834
+ if (__DEV__) {
1835
+ expect(console.error.calls.count()).toBe(1);
1836
+ }
1837
1838
ReactDOMServer.renderToString(<div onfocusout={() => {}} />);
1742
- expectDev(console.error.calls.count()).toBe(2);
1839
+ if (__DEV__) {
1840
+ expect(console.error.calls.count()).toBe(2);
1841
+ }
1842
});
1843
1844
it('gives source code refs for unknown prop warning', () => {
1746
- spyOn(console, 'error');
1845
+ spyOnDev(console, 'error');
1846
ReactTestUtils.renderIntoDocument(<div class="paladin" />);
1847
ReactTestUtils.renderIntoDocument(<input type="text" onclick="1" />);
1749
- expectDev(console.error.calls.count()).toBe(2);
1750
- expectDev(normalizeCodeLocInfo(console.error.calls.argsFor(0)[0])).toBe(
1751
- 'Warning: Invalid DOM property `class`. Did you mean `className`?\n in div (at **)',
1752
- );
1753
- expectDev(normalizeCodeLocInfo(console.error.calls.argsFor(1)[0])).toBe(
1754
- 'Warning: Invalid event handler property `onclick`. Did you mean ' +
1755
- '`onClick`?\n in input (at **)',
1756
- );
1848
+ if (__DEV__) {
1849
+ expect(console.error.calls.count()).toBe(2);
1850
+ expect(normalizeCodeLocInfo(console.error.calls.argsFor(0)[0])).toBe(
1851
+ 'Warning: Invalid DOM property `class`. Did you mean `className`?\n in div (at **)',
1852
+ );
1853
+ expect(normalizeCodeLocInfo(console.error.calls.argsFor(1)[0])).toBe(
1854
+ 'Warning: Invalid event handler property `onclick`. Did you mean ' +
1855
+ '`onClick`?\n in input (at **)',
1856
+ );
1857
+ }
1858
});
1859
1860
it('gives source code refs for unknown prop warning (ssr)', () => {
1760
- spyOn(console, 'error');
1861
+ spyOnDev(console, 'error');
1862
ReactDOMServer.renderToString(<div class="paladin" />);
1863
ReactDOMServer.renderToString(<input type="text" onclick="1" />);
1763
- expectDev(console.error.calls.count()).toBe(2);
1764
- expectDev(normalizeCodeLocInfo(console.error.calls.argsFor(0)[0])).toBe(
1765
- 'Warning: Invalid DOM property `class`. Did you mean `className`?\n in div (at **)',
1766
- );
1767
- expectDev(normalizeCodeLocInfo(console.error.calls.argsFor(1)[0])).toBe(
1768
- 'Warning: Invalid event handler property `onclick`. Did you mean ' +
1769
- '`onClick`?\n in input (at **)',
1770
- );
1864
+ if (__DEV__) {
1865
+ expect(console.error.calls.count()).toBe(2);
1866
+ expect(normalizeCodeLocInfo(console.error.calls.argsFor(0)[0])).toBe(
1867
+ 'Warning: Invalid DOM property `class`. Did you mean `className`?\n in div (at **)',
1868
+ );
1869
+ expect(normalizeCodeLocInfo(console.error.calls.argsFor(1)[0])).toBe(
1870
+ 'Warning: Invalid event handler property `onclick`. Did you mean ' +
1871
+ '`onClick`?\n in input (at **)',
1872
+ );
1873
+ }
1874
});
1875
1876
it('gives source code refs for unknown prop warning for update render', () => {
1774
- spyOn(console, 'error');
1877
+ spyOnDev(console, 'error');
1878
var container = document.createElement('div');
1879
1880
ReactTestUtils.renderIntoDocument(<div className="paladin" />, container);
1778
- expectDev(console.error.calls.count()).toBe(0);
1881
+ if (__DEV__) {
1882
+ expect(console.error.calls.count()).toBe(0);
1883
+ }
1884
1885
ReactTestUtils.renderIntoDocument(<div class="paladin" />, container);
1781
- expectDev(console.error.calls.count()).toBe(1);
1782
- expectDev(normalizeCodeLocInfo(console.error.calls.argsFor(0)[0])).toBe(
1783
- 'Warning: Invalid DOM property `class`. Did you mean `className`?\n in div (at **)',
1784
- );
1886
+ if (__DEV__) {
1887
+ expect(console.error.calls.count()).toBe(1);
1888
+ expect(normalizeCodeLocInfo(console.error.calls.argsFor(0)[0])).toBe(
1889
+ 'Warning: Invalid DOM property `class`. Did you mean `className`?\n in div (at **)',
1890
+ );
1891
+ }
1892
});
1893
1894
it('gives source code refs for unknown prop warning for exact elements', () => {
1788
- spyOn(console, 'error');
1895
+ spyOnDev(console, 'error');
1896
1897
ReactTestUtils.renderIntoDocument(
1898
<div className="foo1">
1904
</div>,
1905
);
1906
1800
- expectDev(console.error.calls.count()).toBe(2);
1907
+ if (__DEV__) {
1908
+ expect(console.error.calls.count()).toBe(2);
1909
1802
- expectDev(console.error.calls.argsFor(0)[0]).toContain('className');
1803
- var matches = console.error.calls.argsFor(0)[0].match(/.*\(.*:(\d+)\).*/);
1804
- var previousLine = matches[1];
1910
+ expect(console.error.calls.argsFor(0)[0]).toContain('className');
1911
+ var matches = console.error.calls
1912
+ .argsFor(0)[0]
1913
+ .match(/.*\(.*:(\d+)\).*/);
1914
+ var previousLine = matches[1];
1915
1806
- expectDev(console.error.calls.argsFor(1)[0]).toContain('onClick');
1807
- matches = console.error.calls.argsFor(1)[0].match(/.*\(.*:(\d+)\).*/);
1808
- var currentLine = matches[1];
1916
+ expect(console.error.calls.argsFor(1)[0]).toContain('onClick');
1917
+ matches = console.error.calls.argsFor(1)[0].match(/.*\(.*:(\d+)\).*/);
1918
+ var currentLine = matches[1];
1919
1810
- //verify line number has a proper relative difference,
1811
- //since hard coding the line number would make test too brittle
1812
- expect(parseInt(previousLine, 10) + 2).toBe(parseInt(currentLine, 10));
1920
+ //verify line number has a proper relative difference,
1921
+ //since hard coding the line number would make test too brittle
1922
+ expect(parseInt(previousLine, 10) + 2).toBe(parseInt(currentLine, 10));
1923
+ }
1924
});
1925
1926
it('gives source code refs for unknown prop warning for exact elements (ssr)', () => {
1816
- spyOn(console, 'error');
1927
+ spyOnDev(console, 'error');
1928
1929
ReactDOMServer.renderToString(
1930
<div className="foo1">
1936
</div>,
1937
);
1938
1828
- expectDev(console.error.calls.count()).toBe(2);
1939
+ if (__DEV__) {
1940
+ expect(console.error.calls.count()).toBe(2);
1941
1830
- expectDev(console.error.calls.argsFor(0)[0]).toContain('className');
1831
- var matches = console.error.calls.argsFor(0)[0].match(/.*\(.*:(\d+)\).*/);
1832
- var previousLine = (matches || [])[1];
1942
+ expect(console.error.calls.argsFor(0)[0]).toContain('className');
1943
+ var matches = console.error.calls
1944
+ .argsFor(0)[0]
1945
+ .match(/.*\(.*:(\d+)\).*/);
1946
+ var previousLine = (matches || [])[1];
1947
1834
- expectDev(console.error.calls.argsFor(1)[0]).toContain('onClick');
1835
- matches =
1836
- console.error.calls.argsFor(1)[0].match(/.*\(.*:(\d+)\).*/) || {};
1837
- var currentLine = (matches || [])[1];
1948
+ expect(console.error.calls.argsFor(1)[0]).toContain('onClick');
1949
+ matches =
1950
+ console.error.calls.argsFor(1)[0].match(/.*\(.*:(\d+)\).*/) || {};
1951
+ var currentLine = (matches || [])[1];
1952
1839
- //verify line number has a proper relative difference,
1840
- //since hard coding the line number would make test too brittle
1841
- expectDev(parseInt(previousLine, 10) + 2).toBe(parseInt(currentLine, 10));
1953
+ //verify line number has a proper relative difference,
1954
+ //since hard coding the line number would make test too brittle
1955
+ expect(parseInt(previousLine, 10) + 2).toBe(parseInt(currentLine, 10));
1956
+ }
1957
});
1958
1959
it('gives source code refs for unknown prop warning for exact elements in composition', () => {
1845
- spyOn(console, 'error');
1960
+ spyOnDev(console, 'error');
1961
var container = document.createElement('div');
1962
1963
class Parent extends React.Component {
1999
2000
ReactTestUtils.renderIntoDocument(<Parent />, container);
2001
1887
- expectDev(console.error.calls.count()).toBe(2);
2002
+ if (__DEV__) {
2003
+ expect(console.error.calls.count()).toBe(2);
2004
1889
- expectDev(console.error.calls.argsFor(0)[0]).toContain('className');
1890
- var matches = console.error.calls.argsFor(0)[0].match(/.*\(.*:(\d+)\).*/);
1891
- var previousLine = (matches || [])[1];
2005
+ expect(console.error.calls.argsFor(0)[0]).toContain('className');
2006
+ var matches = console.error.calls
2007
+ .argsFor(0)[0]
2008
+ .match(/.*\(.*:(\d+)\).*/);
2009
+ var previousLine = (matches || [])[1];
2010
1893
- expectDev(console.error.calls.argsFor(1)[0]).toContain('onClick');
1894
- matches = console.error.calls.argsFor(1)[0].match(/.*\(.*:(\d+)\).*/);
1895
- var currentLine = (matches || [])[1];
2011
+ expect(console.error.calls.argsFor(1)[0]).toContain('onClick');
2012
+ matches = console.error.calls.argsFor(1)[0].match(/.*\(.*:(\d+)\).*/);
2013
+ var currentLine = (matches || [])[1];
2014
1897
- //verify line number has a proper relative difference,
1898
- //since hard coding the line number would make test too brittle
1899
- expect(parseInt(previousLine, 10) + 12).toBe(parseInt(currentLine, 10));
2015
+ //verify line number has a proper relative difference,
2016
+ //since hard coding the line number would make test too brittle
2017
+ expect(parseInt(previousLine, 10) + 12).toBe(parseInt(currentLine, 10));
2018
+ }
2019
});
2020
2021
it('gives source code refs for unknown prop warning for exact elements in composition (ssr)', () => {
1903
- spyOn(console, 'error');
2022
+ spyOnDev(console, 'error');
2023
var container = document.createElement('div');
2024
2025
class Parent extends React.Component {
2061
2062
ReactDOMServer.renderToString(<Parent />, container);
2063
1945
- expectDev(console.error.calls.count()).toBe(2);
2064
+ if (__DEV__) {
2065
+ expect(console.error.calls.count()).toBe(2);
2066
1947
- expectDev(console.error.calls.argsFor(0)[0]).toContain('className');
1948
- var matches = console.error.calls.argsFor(0)[0].match(/.*\(.*:(\d+)\).*/);
1949
- var previousLine = (matches || [])[1];
2067
+ expect(console.error.calls.argsFor(0)[0]).toContain('className');
2068
+ var matches = console.error.calls
2069
+ .argsFor(0)[0]
2070
+ .match(/.*\(.*:(\d+)\).*/);
2071
+ var previousLine = (matches || [])[1];
2072
1951
- expectDev(console.error.calls.argsFor(1)[0]).toContain('onClick');
1952
- matches = console.error.calls.argsFor(1)[0].match(/.*\(.*:(\d+)\).*/);
1953
- var currentLine = (matches || [])[1];
2073
+ expect(console.error.calls.argsFor(1)[0]).toContain('onClick');
2074
+ matches = console.error.calls.argsFor(1)[0].match(/.*\(.*:(\d+)\).*/);
2075
+ var currentLine = (matches || [])[1];
2076
1955
- //verify line number has a proper relative difference,
1956
- //since hard coding the line number would make test too brittle
1957
- expectDev(parseInt(previousLine, 10) + 12).toBe(
1958
- parseInt(currentLine, 10),
1959
- );
2077
+ //verify line number has a proper relative difference,
2078
+ //since hard coding the line number would make test too brittle
2079
+ expect(parseInt(previousLine, 10) + 12).toBe(parseInt(currentLine, 10));
2080
+ }
2081
});
2082
2083
it('should suggest property name if available', () => {
1963
- spyOn(console, 'error');
2084
+ spyOnDev(console, 'error');
2085
2086
ReactTestUtils.renderIntoDocument(
2087
React.createElement('label', {for: 'test'}),
2090
React.createElement('input', {type: 'text', autofocus: true}),
2091
);
2092
1972
- expectDev(console.error.calls.count()).toBe(2);
2093
+ if (__DEV__) {
2094
+ expect(console.error.calls.count()).toBe(2);
2095
1974
- expectDev(console.error.calls.argsFor(0)[0]).toBe(
1975
- 'Warning: Invalid DOM property `for`. Did you mean `htmlFor`?\n in label',
1976
- );
2096
+ expect(console.error.calls.argsFor(0)[0]).toBe(
2097
+ 'Warning: Invalid DOM property `for`. Did you mean `htmlFor`?\n in label',
2098
+ );
2099
1978
- expectDev(console.error.calls.argsFor(1)[0]).toBe(
1979
- 'Warning: Invalid DOM property `autofocus`. Did you mean `autoFocus`?\n in input',
1980
- );
2100
+ expect(console.error.calls.argsFor(1)[0]).toBe(
2101
+ 'Warning: Invalid DOM property `autofocus`. Did you mean `autoFocus`?\n in input',
2102
+ );
2103
+ }
2104
});
2105
2106
it('should suggest property name if available (ssr)', () => {
1984
- spyOn(console, 'error');
2107
+ spyOnDev(console, 'error');
2108
2109
ReactDOMServer.renderToString(
2110
React.createElement('label', {for: 'test'}),
2113
React.createElement('input', {type: 'text', autofocus: true}),
2114
);
2115
1993
- expectDev(console.error.calls.count()).toBe(2);
2116
+ if (__DEV__) {
2117
+ expect(console.error.calls.count()).toBe(2);
2118
1995
- expectDev(console.error.calls.argsFor(0)[0]).toBe(
1996
- 'Warning: Invalid DOM property `for`. Did you mean `htmlFor`?\n in label',
1997
- );
2119
+ expect(console.error.calls.argsFor(0)[0]).toBe(
2120
+ 'Warning: Invalid DOM property `for`. Did you mean `htmlFor`?\n in label',
2121
+ );
2122
1999
- expectDev(console.error.calls.argsFor(1)[0]).toBe(
2000
- 'Warning: Invalid DOM property `autofocus`. Did you mean `autoFocus`?\n in input',
2001
- );
2123
+ expect(console.error.calls.argsFor(1)[0]).toBe(
2124
+ 'Warning: Invalid DOM property `autofocus`. Did you mean `autoFocus`?\n in input',
2125
+ );
2126
+ }
2127
});
2128
});
2129
2153
2154
describe('Attributes with aliases', function() {
2155
it('sets aliased attributes on HTML attributes', function() {
2031
- spyOn(console, 'error');
2156
+ spyOnDev(console, 'error');
2157
2158
var el = ReactTestUtils.renderIntoDocument(<div class="test" />);
2159
2160
expect(el.className).toBe('test');
2161
2037
- expectDev(console.error.calls.argsFor(0)[0]).toContain(
2038
- 'Warning: Invalid DOM property `class`. Did you mean `className`?',
2039
- );
2162
+ if (__DEV__) {
2163
+ expect(console.error.calls.argsFor(0)[0]).toContain(
2164
+ 'Warning: Invalid DOM property `class`. Did you mean `className`?',
2165
+ );
2166
+ }
2167
});
2168
2169
it('sets incorrectly cased aliased attributes on HTML attributes with a warning', function() {
2043
- spyOn(console, 'error');
2170
+ spyOnDev(console, 'error');
2171
2172
var el = ReactTestUtils.renderIntoDocument(<div cLASS="test" />);
2173
2174
expect(el.className).toBe('test');
2175
2049
- expectDev(console.error.calls.argsFor(0)[0]).toContain(
2050
- 'Warning: Invalid DOM property `cLASS`. Did you mean `className`?',
2051
- );
2176
+ if (__DEV__) {
2177
+ expect(console.error.calls.argsFor(0)[0]).toContain(
2178
+ 'Warning: Invalid DOM property `cLASS`. Did you mean `className`?',
2179
+ );
2180
+ }
2181
});
2182
2183
it('sets aliased attributes on SVG elements with a warning', function() {
2055
- spyOn(console, 'error');
2184
+ spyOnDev(console, 'error');
2185
2186
var el = ReactTestUtils.renderIntoDocument(
2187
<svg>
2192
2193
expect(text.hasAttribute('arabic-form')).toBe(true);
2194
2066
- expectDev(console.error.calls.argsFor(0)[0]).toContain(
2067
- 'Warning: Invalid DOM property `arabic-form`. Did you mean `arabicForm`?',
2068
- );
2195
+ if (__DEV__) {
2196
+ expect(console.error.calls.argsFor(0)[0]).toContain(
2197
+ 'Warning: Invalid DOM property `arabic-form`. Did you mean `arabicForm`?',
2198
+ );
2199
+ }
2200
});
2201
2202
it('sets aliased attributes on custom elements', function() {
2243
});
2244
2245
it('does not assign a boolean custom attributes as a string', function() {
2115
- spyOn(console, 'error');
2246
+ spyOnDev(console, 'error');
2247
2248
var el = ReactTestUtils.renderIntoDocument(<div whatever={true} />);
2249
2250
expect(el.hasAttribute('whatever')).toBe(false);
2251
2121
- expectDev(console.error.calls.argsFor(0)[0]).toContain(
2122
- 'Received `true` for a non-boolean attribute `whatever`.\n\n' +
2123
- 'If you want to write it to the DOM, pass a string instead: ' +
2124
- 'whatever="true" or whatever={value.toString()}.',
2125
- );
2252
+ if (__DEV__) {
2253
+ expect(console.error.calls.argsFor(0)[0]).toContain(
2254
+ 'Received `true` for a non-boolean attribute `whatever`.\n\n' +
2255
+ 'If you want to write it to the DOM, pass a string instead: ' +
2256
+ 'whatever="true" or whatever={value.toString()}.',
2257
+ );
2258
+ }
2259
});
2260
2261
it('does not assign an implicit boolean custom attributes', function() {
2129
- spyOn(console, 'error');
2262
+ spyOnDev(console, 'error');
2263
2264
// eslint-disable-next-line react/jsx-boolean-value
2265
var el = ReactTestUtils.renderIntoDocument(<div whatever />);
2266
2267
expect(el.hasAttribute('whatever')).toBe(false);
2268
2136
- expectDev(console.error.calls.argsFor(0)[0]).toContain(
2137
- 'Received `true` for a non-boolean attribute `whatever`.\n\n' +
2138
- 'If you want to write it to the DOM, pass a string instead: ' +
2139
- 'whatever="true" or whatever={value.toString()}.',
2140
- );
2269
+ if (__DEV__) {
2270
+ expect(console.error.calls.argsFor(0)[0]).toContain(
2271
+ 'Received `true` for a non-boolean attribute `whatever`.\n\n' +
2272
+ 'If you want to write it to the DOM, pass a string instead: ' +
2273
+ 'whatever="true" or whatever={value.toString()}.',
2274
+ );
2275
+ }
2276
});
2277
2278
it('assigns a numeric custom attributes as a string', function() {
2282
});
2283
2284
it('will not assign a function custom attributes', function() {
2150
- spyOn(console, 'error');
2285
+ spyOnDev(console, 'error');
2286
2287
var el = ReactTestUtils.renderIntoDocument(<div whatever={() => {}} />);
2288
2289
expect(el.hasAttribute('whatever')).toBe(false);
2290
2156
- expectDev(console.error.calls.argsFor(0)[0]).toContain(
2157
- 'Warning: Invalid value for prop `whatever` on <div> tag',
2158
- );
2291
+ if (__DEV__) {
2292
+ expect(console.error.calls.argsFor(0)[0]).toContain(
2293
+ 'Warning: Invalid value for prop `whatever` on <div> tag',
2294
+ );
2295
+ }
2296
});
2297
2298
it('will assign an object custom attributes', function() {
2301
});
2302
2303
it('allows cased data attributes', function() {
2167
- spyOn(console, 'error');
2304
+ spyOnDev(console, 'error');
2305
2306
var el = ReactTestUtils.renderIntoDocument(<div data-fooBar="true" />);
2307
expect(el.getAttribute('data-foobar')).toBe('true');
2308
2172
- expectDev(console.error.calls.count()).toBe(1);
2173
- expectDev(
2174
- normalizeCodeLocInfo(console.error.calls.argsFor(0)[0]),
2175
- ).toMatch(
2176
- 'React does not recognize the `data-fooBar` prop on a DOM element. ' +
2177
- 'If you intentionally want it to appear in the DOM as a custom ' +
2178
- 'attribute, spell it as lowercase `data-foobar` instead. ' +
2179
- 'If you accidentally passed it from a parent component, remove ' +
2180
- 'it from the DOM element.\n' +
2181
- ' in div (at **)',
2182
- );
2309
+ if (__DEV__) {
2310
+ expect(console.error.calls.count()).toBe(1);
2311
+ expect(normalizeCodeLocInfo(console.error.calls.argsFor(0)[0])).toMatch(
2312
+ 'React does not recognize the `data-fooBar` prop on a DOM element. ' +
2313
+ 'If you intentionally want it to appear in the DOM as a custom ' +
2314
+ 'attribute, spell it as lowercase `data-foobar` instead. ' +
2315
+ 'If you accidentally passed it from a parent component, remove ' +
2316
+ 'it from the DOM element.\n' +
2317
+ ' in div (at **)',
2318
+ );
2319
+ }
2320
});
2321
2322
it('allows cased custom attributes', function() {
2186
- spyOn(console, 'error');
2323
+ spyOnDev(console, 'error');
2324
2325
var el = ReactTestUtils.renderIntoDocument(<div fooBar="true" />);
2326
expect(el.getAttribute('foobar')).toBe('true');
2327
2191
- expectDev(console.error.calls.count()).toBe(1);
2192
- expectDev(
2193
- normalizeCodeLocInfo(console.error.calls.argsFor(0)[0]),
2194
- ).toMatch(
2195
- 'React does not recognize the `fooBar` prop on a DOM element. ' +
2196
- 'If you intentionally want it to appear in the DOM as a custom ' +
2197
- 'attribute, spell it as lowercase `foobar` instead. ' +
2198
- 'If you accidentally passed it from a parent component, remove ' +
2199
- 'it from the DOM element.\n' +
2200
- ' in div (at **)',
2201
- );
2328
+ if (__DEV__) {
2329
+ expect(console.error.calls.count()).toBe(1);
2330
+ expect(normalizeCodeLocInfo(console.error.calls.argsFor(0)[0])).toMatch(
2331
+ 'React does not recognize the `fooBar` prop on a DOM element. ' +
2332
+ 'If you intentionally want it to appear in the DOM as a custom ' +
2333
+ 'attribute, spell it as lowercase `foobar` instead. ' +
2334
+ 'If you accidentally passed it from a parent component, remove ' +
2335
+ 'it from the DOM element.\n' +
2336
+ ' in div (at **)',
2337
+ );
2338
+ }
2339
});
2340
2341
it('warns on NaN attributes', function() {
2205
- spyOn(console, 'error');
2342
+ spyOnDev(console, 'error');
2343
2344
var el = ReactTestUtils.renderIntoDocument(<div whatever={NaN} />);
2345
2346
expect(el.getAttribute('whatever')).toBe('NaN');
2347
2211
- expectDev(console.error.calls.argsFor(0)[0]).toContain(
2212
- 'Warning: Received NaN for the `whatever` attribute. If this is ' +
2213
- 'expected, cast the value to a string.\n in div',
2214
- );
2348
+ if (__DEV__) {
2349
+ expect(console.error.calls.argsFor(0)[0]).toContain(
2350
+ 'Warning: Received NaN for the `whatever` attribute. If this is ' +
2351
+ 'expected, cast the value to a string.\n in div',
2352
+ );
2353
+ }
2354
});
2355
2356
it('removes a property when it becomes invalid', function() {
2218
- spyOn(console, 'error');
2357
+ spyOnDev(console, 'error');
2358
2359
var container = document.createElement('div');
2360
ReactDOM.render(<div whatever={0} />, container);
2363
2364
expect(el.hasAttribute('whatever')).toBe(false);
2365
2227
- expectDev(console.error.calls.argsFor(0)[0]).toContain(
2228
- 'Warning: Invalid value for prop `whatever` on <div> tag.',
2229
- );
2366
+ if (__DEV__) {
2367
+ expect(console.error.calls.argsFor(0)[0]).toContain(
2368
+ 'Warning: Invalid value for prop `whatever` on <div> tag.',
2369
+ );
2370
+ }
2371
});
2372
2373
it('warns on bad casing of known HTML attributes', function() {
2233
- spyOn(console, 'error');
2374
+ spyOnDev(console, 'error');
2375
2376
var el = ReactTestUtils.renderIntoDocument(<div SiZe="30" />);
2377
2378
expect(el.getAttribute('size')).toBe('30');
2379
2239
- expectDev(console.error.calls.argsFor(0)[0]).toContain(
2240
- 'Warning: Invalid DOM property `SiZe`. Did you mean `size`?',
2241
- );
2380
+ if (__DEV__) {
2381
+ expect(console.error.calls.argsFor(0)[0]).toContain(
2382
+ 'Warning: Invalid DOM property `SiZe`. Did you mean `size`?',
2383
+ );
2384
+ }
2385
});
2386
});
2387
2447
2448
describe('String boolean attributes', function() {
2449
it('does not assign string boolean attributes for custom attributes', function() {
2307
- spyOn(console, 'error');
2450
+ spyOnDev(console, 'error');
2451
2452
var el = ReactTestUtils.renderIntoDocument(<div whatever={true} />);
2453
2454
expect(el.hasAttribute('whatever')).toBe(false);
2455
2313
- expectDev(console.error.calls.argsFor(0)[0]).toContain(
2314
- 'Received `true` for a non-boolean attribute `whatever`.\n\n' +
2315
- 'If you want to write it to the DOM, pass a string instead: ' +
2316
- 'whatever="true" or whatever={value.toString()}.',
2317
- );
2456
+ if (__DEV__) {
2457
+ expect(console.error.calls.argsFor(0)[0]).toContain(
2458
+ 'Received `true` for a non-boolean attribute `whatever`.\n\n' +
2459
+ 'If you want to write it to the DOM, pass a string instead: ' +
2460
+ 'whatever="true" or whatever={value.toString()}.',
2461
+ );
2462
+ }
2463
});
2464
2465
it('stringifies the boolean true for allowed attributes', function() {
2484
2485
describe('Hyphenated SVG elements', function() {
2486
it('the font-face element is not a custom element', function() {
2342
- spyOn(console, 'error');
2487
+ spyOnDev(console, 'error');
2488
var el = ReactTestUtils.renderIntoDocument(
2489
<svg>
2490
<font-face x-height={false} />
2495
false,
2496
);
2497
2353
- expectDev(console.error.calls.count()).toBe(1);
2354
- expectDev(console.error.calls.argsFor(0)[0]).toContain(
2355
- 'Warning: Invalid DOM property `x-height`. Did you mean `xHeight`',
2356
- );
2498
+ if (__DEV__) {
2499
+ expect(console.error.calls.count()).toBe(1);
2500
+ expect(console.error.calls.argsFor(0)[0]).toContain(
2501
+ 'Warning: Invalid DOM property `x-height`. Did you mean `xHeight`',
2502
+ );
2503
+ }
2504
});
2505
2506
it('the font-face element does not allow unknown boolean values', function() {
2360
- spyOn(console, 'error');
2507
+ spyOnDev(console, 'error');
2508
var el = ReactTestUtils.renderIntoDocument(
2509
<svg>
2510
<font-face whatever={false} />
2515
false,
2516
);
2517
2371
- expectDev(console.error.calls.count()).toBe(1);
2372
- expectDev(console.error.calls.argsFor(0)[0]).toContain(
2373
- 'Received `false` for a non-boolean attribute `whatever`.\n\n' +
2374
- 'If you want to write it to the DOM, pass a string instead: ' +
2375
- 'whatever="false" or whatever={value.toString()}.\n\n' +
2376
- 'If you used to conditionally omit it with whatever={condition && value}, ' +
2377
- 'pass whatever={condition ? value : undefined} instead.',
2378
- );
2518
+ if (__DEV__) {
2519
+ expect(console.error.calls.count()).toBe(1);
2520
+ expect(console.error.calls.argsFor(0)[0]).toContain(
2521
+ 'Received `false` for a non-boolean attribute `whatever`.\n\n' +
2522
+ 'If you want to write it to the DOM, pass a string instead: ' +
2523
+ 'whatever="false" or whatever={value.toString()}.\n\n' +
2524
+ 'If you used to conditionally omit it with whatever={condition && value}, ' +
2525
+ 'pass whatever={condition ? value : undefined} instead.',
2526
+ );
2527
+ }
2528
});
2529
});
2530
});