Skip to content

Commit fc96f31

Browse files
committed
Merge pull request facebook#5185 from yungsters/invariant
Remove "Invariant Violation: " from Invariant Error Messages
2 parents 244dd5d + 278939e commit fc96f31

30 files changed

+149
-194
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"eslint": "^1.5.1",
1616
"eslint-plugin-react": "^3.4.2",
1717
"eslint-plugin-react-internal": "file:eslint-rules",
18-
"fbjs": "^0.3.1",
18+
"fbjs": "^0.4.0",
1919
"fbjs-scripts": "^0.2.0",
2020
"grunt": "^0.4.5",
2121
"grunt-cli": "^0.1.13",

src/addons/__tests__/ReactFragment-test.js

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,10 @@ describe('ReactFragment', function() {
3232
var element = <div>{[children]}</div>;
3333
var container = document.createElement('div');
3434
expect(() => ReactDOM.render(element, container)).toThrow(
35-
'Invariant Violation: Objects are not valid as a React child (found: ' +
36-
'object with keys {x, y, z}). If you meant to render a collection of ' +
37-
'children, use an array instead or wrap the object using ' +
38-
'createFragment(object) from the React add-ons.'
35+
'Objects are not valid as a React child (found: object with keys ' +
36+
'{x, y, z}). If you meant to render a collection of children, use an ' +
37+
'array instead or wrap the object using createFragment(object) from ' +
38+
'the React add-ons.'
3939
);
4040
});
4141

@@ -52,22 +52,21 @@ describe('ReactFragment', function() {
5252
}
5353
var container = document.createElement('div');
5454
expect(() => ReactDOM.render(<Foo />, container)).toThrow(
55-
'Invariant Violation: Objects are not valid as a React child (found: ' +
56-
'object with keys {a, b, c}). If you meant to render a collection of ' +
57-
'children, use an array instead or wrap the object using ' +
58-
'createFragment(object) from the React add-ons. Check the render ' +
59-
'method of `Foo`.'
55+
'Objects are not valid as a React child (found: object with keys ' +
56+
'{a, b, c}). If you meant to render a collection of children, use an ' +
57+
'array instead or wrap the object using createFragment(object) from ' +
58+
'the React add-ons. Check the render method of `Foo`.'
6059
);
6160
});
6261

6362
it('should throw if a plain object looks like an old element', function() {
6463
var oldEl = {_isReactElement: true, type: 'span', props: {}};
6564
var container = document.createElement('div');
6665
expect(() => ReactDOM.render(<div>{oldEl}</div>, container)).toThrow(
67-
'Invariant Violation: Objects are not valid as a React child (found: ' +
68-
'object with keys {_isReactElement, type, props}). It looks like ' +
69-
'you\'re using an element created by a different version of React. ' +
70-
'Make sure to use only one copy of React.'
66+
'Objects are not valid as a React child (found: object with keys ' +
67+
'{_isReactElement, type, props}). It looks like you\'re using an ' +
68+
'element created by a different version of React. Make sure to use ' +
69+
'only one copy of React.'
7170
);
7271
});
7372

src/addons/__tests__/renderSubtreeIntoContainer-test.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,7 @@ describe('renderSubtreeIntoContainer', function() {
8888
componentDidMount: function() {
8989
expect(function() {
9090
renderSubtreeIntoContainer(<Parent />, <Component />, portal);
91-
}).toThrow('Invariant Violation: parentComponent' +
92-
'must be a valid React Component');
91+
}).toThrow('parentComponentmust be a valid React Component');
9392
},
9493
});
9594
});

src/addons/__tests__/update-test.js

Lines changed: 17 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -17,53 +17,47 @@ describe('update', function() {
1717
it('should support push', function() {
1818
expect(update([1], {$push: [7]})).toEqual([1, 7]);
1919
expect(update.bind(null, [], {$push: 7})).toThrow(
20-
'Invariant Violation: update(): expected spec of $push to be an ' +
21-
'array; got 7. Did you forget to wrap your parameter in an array?'
20+
'update(): expected spec of $push to be an array; got 7. Did you ' +
21+
'forget to wrap your parameter in an array?'
2222
);
2323
expect(update.bind(null, 1, {$push: 7})).toThrow(
24-
'Invariant Violation: update(): expected target of $push to be an ' +
25-
'array; got 1.'
24+
'update(): expected target of $push to be an array; got 1.'
2625
);
2726
});
2827

2928
it('should support unshift', function() {
3029
expect(update([1], {$unshift: [7]})).toEqual([7, 1]);
3130
expect(update.bind(null, [], {$unshift: 7})).toThrow(
32-
'Invariant Violation: update(): expected spec of $unshift to be an ' +
33-
'array; got 7. Did you forget to wrap your parameter in an array?'
31+
'update(): expected spec of $unshift to be an array; got 7. Did you ' +
32+
'forget to wrap your parameter in an array?'
3433
);
3534
expect(update.bind(null, 1, {$unshift: 7})).toThrow(
36-
'Invariant Violation: update(): expected target of $unshift to be an ' +
37-
'array; got 1.'
35+
'update(): expected target of $unshift to be an array; got 1.'
3836
);
3937
});
4038

4139
it('should support splice', function() {
4240
expect(update([1, 4, 3], {$splice: [[1, 1, 2]]})).toEqual([1, 2, 3]);
4341
expect(update.bind(null, [], {$splice: 1})).toThrow(
44-
'Invariant Violation: update(): expected spec of $splice to be an ' +
45-
'array of arrays; got 1. Did you forget to wrap your parameters in an ' +
46-
'array?'
42+
'update(): expected spec of $splice to be an array of arrays; got 1. ' +
43+
'Did you forget to wrap your parameters in an array?'
4744
);
4845
expect(update.bind(null, [], {$splice: [1]})).toThrow(
49-
'Invariant Violation: update(): expected spec of $splice to be an ' +
50-
'array of arrays; got 1. Did you forget to wrap your parameters in an ' +
51-
'array?'
46+
'update(): expected spec of $splice to be an array of arrays; got 1. ' +
47+
'Did you forget to wrap your parameters in an array?'
5248
);
5349
expect(update.bind(null, 1, {$splice: 7})).toThrow(
54-
'Invariant Violation: Expected $splice target to be an array; got 1'
50+
'Expected $splice target to be an array; got 1'
5551
);
5652
});
5753

5854
it('should support merge', function() {
5955
expect(update({a: 'b'}, {$merge: {c: 'd'}})).toEqual({a: 'b', c: 'd'});
6056
expect(update.bind(null, {}, {$merge: 7})).toThrow(
61-
'Invariant Violation: update(): $merge expects a spec of type ' +
62-
'\'object\'; got 7'
57+
'update(): $merge expects a spec of type \'object\'; got 7'
6358
);
6459
expect(update.bind(null, 7, {$merge: {a: 'b'}})).toThrow(
65-
'Invariant Violation: update(): $merge expects a target of type ' +
66-
'\'object\'; got 7'
60+
'update(): $merge expects a target of type \'object\'; got 7'
6761
);
6862
});
6963

@@ -74,8 +68,7 @@ describe('update', function() {
7468
it('should support apply', function() {
7569
expect(update(2, {$apply: (x) => x * 2})).toEqual(4);
7670
expect(update.bind(null, 2, {$apply: 123})).toThrow(
77-
'Invariant Violation: update(): expected spec of $apply to be a ' +
78-
'function; got 123.'
71+
'update(): expected spec of $apply to be a function; got 123.'
7972
);
8073
});
8174

@@ -88,9 +81,9 @@ describe('update', function() {
8881

8982
it('should require a command', function() {
9083
expect(update.bind(null, {a: 'b'}, {a: 'c'})).toThrow(
91-
'Invariant Violation: update(): You provided a key path to update() ' +
92-
'that did not contain one of $push, $unshift, $splice, $set, $merge, ' +
93-
'$apply. Did you forget to include {$set: ...}?'
84+
'update(): You provided a key path to update() that did not contain ' +
85+
'one of $push, $unshift, $splice, $set, $merge, $apply. Did you ' +
86+
'forget to include {$set: ...}?'
9487
);
9588
});
9689

src/isomorphic/classic/class/__tests__/ReactClass-test.js

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,7 @@ describe('ReactClass-spec', function() {
3030
expect(function() {
3131
React.createClass({});
3232
}).toThrow(
33-
'Invariant Violation: createClass(...): Class specification must ' +
34-
'implement a `render` method.'
33+
'createClass(...): Class specification must implement a `render` method.'
3534
);
3635
});
3736

@@ -197,10 +196,10 @@ describe('ReactClass-spec', function() {
197196
},
198197
});
199198
}).toThrow(
200-
'Invariant Violation: ReactClass: You are attempting to ' +
201-
'define a reserved property, `getDefaultProps`, that shouldn\'t be on ' +
202-
'the "statics" key. Define it as an instance property instead; it ' +
203-
'will still be accessible on the constructor.'
199+
'ReactClass: You are attempting to define a reserved property, ' +
200+
'`getDefaultProps`, that shouldn\'t be on the "statics" key. Define ' +
201+
'it as an instance property instead; it will still be accessible on ' +
202+
'the constructor.'
204203
);
205204
});
206205

@@ -331,8 +330,7 @@ describe('ReactClass-spec', function() {
331330
expect(function() {
332331
instance = ReactTestUtils.renderIntoDocument(instance);
333332
}).toThrow(
334-
'Invariant Violation: Component.getInitialState(): ' +
335-
'must return an object or null'
333+
'Component.getInitialState(): must return an object or null'
336334
);
337335
});
338336
});

src/isomorphic/classic/class/__tests__/ReactClassMixin-test.js

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -208,11 +208,10 @@ describe('ReactClass-mixin', function() {
208208
expect(function() {
209209
instance = ReactTestUtils.renderIntoDocument(instance);
210210
}).toThrow(
211-
'Invariant Violation: mergeIntoWithNoDuplicateKeys(): ' +
212-
'Tried to merge two objects with the same key: `x`. This conflict ' +
213-
'may be due to a mixin; in particular, this may be caused by two ' +
214-
'getInitialState() or getDefaultProps() methods returning objects ' +
215-
'with clashing keys.'
211+
'mergeIntoWithNoDuplicateKeys(): Tried to merge two objects with the ' +
212+
'same key: `x`. This conflict may be due to a mixin; in particular, ' +
213+
'this may be caused by two getInitialState() or getDefaultProps() ' +
214+
'methods returning objects with clashing keys.'
216215
);
217216
});
218217

@@ -280,9 +279,8 @@ describe('ReactClass-mixin', function() {
280279
},
281280
});
282281
}).toThrow(
283-
'Invariant Violation: ReactClass: You are attempting to ' +
284-
'define `abc` on your component more than once. This conflict may be ' +
285-
'due to a mixin.'
282+
'ReactClass: You are attempting to define `abc` on your component more ' +
283+
'than once. This conflict may be due to a mixin.'
286284
);
287285
});
288286

@@ -309,9 +307,8 @@ describe('ReactClass-mixin', function() {
309307
},
310308
});
311309
}).toThrow(
312-
'Invariant Violation: ReactClass: You are attempting to ' +
313-
'define `abc` on your component more than once. This conflict may be ' +
314-
'due to a mixin.'
310+
'ReactClass: You are attempting to define `abc` on your component ' +
311+
'more than once. This conflict may be due to a mixin.'
315312
);
316313
});
317314

@@ -325,8 +322,8 @@ describe('ReactClass-mixin', function() {
325322
},
326323
});
327324
}).toThrow(
328-
'Invariant Violation: ReactClass: You\'re attempting to ' +
329-
'use a component as a mixin. Instead, just use a regular object.'
325+
'ReactClass: You\'re attempting to use a component as a mixin. ' +
326+
'Instead, just use a regular object.'
330327
);
331328
});
332329

@@ -346,9 +343,8 @@ describe('ReactClass-mixin', function() {
346343
},
347344
});
348345
}).toThrow(
349-
'Invariant Violation: ReactClass: You\'re attempting to ' +
350-
'use a component class or function as a mixin. Instead, just use a ' +
351-
'regular object.'
346+
'ReactClass: You\'re attempting to use a component class or function ' +
347+
'as a mixin. Instead, just use a regular object.'
352348
);
353349
});
354350

src/isomorphic/classic/element/__tests__/ReactElementValidator-test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -287,9 +287,9 @@ describe('ReactElementValidator', function() {
287287
expect(function() {
288288
ReactTestUtils.renderIntoDocument(React.createElement(ParentComp));
289289
}).toThrow(
290-
'Invariant Violation: Element type is invalid: expected a string (for ' +
291-
'built-in components) or a class/function (for composite components) ' +
292-
'but got: null. Check the render method of `ParentComp`.'
290+
'Element type is invalid: expected a string (for built-in components) ' +
291+
'or a class/function (for composite components) but got: null. Check ' +
292+
'the render method of `ParentComp`.'
293293
);
294294
expect(console.error.calls.length).toBe(1);
295295
expect(console.error.argsForCall[0][0]).toBe(

src/isomorphic/modern/class/__tests__/ReactCoffeeScriptClass-test.coffee

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ describe 'ReactCoffeeScriptClass', ->
154154
expect(->
155155
test React.createElement(Foo), 'span', ''
156156
).toThrow(
157-
'Invariant Violation: Foo.state: must be set to an object or null'
157+
'Foo.state: must be set to an object or null'
158158
)
159159

160160
it 'should render with null in the initial state property', ->

src/isomorphic/modern/class/__tests__/ReactES6Class-test.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,8 +176,7 @@ describe('ReactES6Class', function() {
176176
}
177177
}
178178
expect(() => test(<Foo />, 'span', '')).toThrow(
179-
'Invariant Violation: Foo.state: ' +
180-
'must be set to an object or null'
179+
'Foo.state: must be set to an object or null'
181180
);
182181
});
183182
});

src/isomorphic/modern/class/__tests__/ReactTypeScriptClass-test.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -361,18 +361,15 @@ describe('ReactTypeScriptClass', function() {
361361
it('should throw with non-object in the initial state property', function() {
362362
expect(() => test(React.createElement(ArrayState), 'span', ''))
363363
.toThrow(
364-
'Invariant Violation: ArrayState.state: ' +
365-
'must be set to an object or null'
364+
'ArrayState.state: must be set to an object or null'
366365
);
367366
expect(() => test(React.createElement(StringState), 'span', ''))
368367
.toThrow(
369-
'Invariant Violation: StringState.state: ' +
370-
'must be set to an object or null'
368+
'StringState.state: must be set to an object or null'
371369
);
372370
expect(() => test(React.createElement(NumberState), 'span', ''))
373371
.toThrow(
374-
'Invariant Violation: NumberState.state: ' +
375-
'must be set to an object or null'
372+
'NumberState.state: must be set to an object or null'
376373
);
377374
});
378375

0 commit comments

Comments
 (0)