Merge pull request #3107 from sebmarkbage/fragments

Warn if a non-object value is used in ReactFragment.create
This commit is contained in:
Sebastian Markbåge
2015-02-11 11:58:46 -08:00
2 changed files with 17 additions and 0 deletions
+8
View File
@@ -96,6 +96,14 @@ var ReactFragment = {
// of its properties.
create: function(object) {
if (__DEV__) {
if (typeof object !== 'object' || !object) {
warning(
false,
'React.addons.createFragment only accepts a single object. Not %s',
object
);
return object;
}
if (canWarnForReactFragment) {
var proxy = {};
Object.defineProperty(proxy, fragmentKey, {
@@ -73,4 +73,13 @@ describe('ReactFragment', function() {
);
});
it('should warn if accessing any property on a fragment', function() {
spyOn(console, 'warn');
ReactFragment.create(null);
expect(console.warn.calls.length).toBe(1);
expect(console.warn.calls[0].args[0]).toContain(
'React.addons.createFragment only accepts a single object. Not null'
);
});
});