mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
Merge pull request #3107 from sebmarkbage/fragments
Warn if a non-object value is used in ReactFragment.create
This commit is contained in:
@@ -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'
|
||||
);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user