More informative error message for mergeObjectsWithNoDuplicateKeys

This commit is contained in:
Charles Marsh 2014-08-13 15:04:19 -04:00
parent ed27c89748
commit dcdc35fab6
2 changed files with 12 additions and 2 deletions

View File

@ -592,7 +592,12 @@ function mergeObjectsWithNoDuplicateKeys(one, two) {
invariant(
one[key] === undefined,
'mergeObjectsWithNoDuplicateKeys(): ' +
'Tried to merge two objects with the same key: %s',
'Tried to merge two objects with the same key: `%s`. ' +
'This conflict may be due to a mixin; in particular, you may be using ' +
'a mixin with its own getDefaultProps() or getInitialState(). This ' +
'could result in both the mixin and base component (or another mixin) ' +
'returning an object (either from getDefaultProps() or ' +
'getInitialState()) with the same key.',
key
);
one[key] = value;

View File

@ -688,7 +688,12 @@ describe('ReactCompositeComponent', function() {
instance = ReactTestUtils.renderIntoDocument(instance);
}).toThrow(
'Invariant Violation: mergeObjectsWithNoDuplicateKeys(): ' +
'Tried to merge two objects with the same key: x'
'Tried to merge two objects with the same key: `x`. ' +
'This conflict may be due to a mixin; in particular, you may be using ' +
'a mixin with its own getDefaultProps() or getInitialState(). This ' +
'could result in both the mixin and base component (or another mixin) ' +
'returning an object (either from getDefaultProps() or ' +
'getInitialState()) with the same key.'
);
});