@samitouri / QOS-React-2 / commits / 5a2c80382c

More warnings to ReactFragment.create

Apparently I could've used these too because if you accept an arbitrary node, then these could end up being objects, but those objects might also be arrays or elements.

Sebastian Markbage committed Feb 19, 2015 at 15:11 UTC 5a2c80382c77dc18d95d66f3840123052d99ffe6
2 files changed +31 -4
src/addons/ReactFragment.js
+10 -2
@@ -96,14 +96,22 @@ var ReactFragment = {
96 // of its properties.
97 create: function(object) {
98 if (__DEV__) {
99 - if (typeof object !== 'object' || !object) {
99 + if (typeof object !== 'object' || !object || Array.isArray(object)) {
100 warning(
101 false,
102 - 'React.addons.createFragment only accepts a single object. Not %s',
102 + 'React.addons.createFragment only accepts a single object.',
103 object
104 );
105 return object;
106 }
107 + if (ReactElement.isValidElement(object)) {
108 + warning(
109 + false,
110 + 'React.addons.createFragment does not accept a ReactElement ' +
111 + 'without a wrapper object.'
112 + );
113 + return object;
114 + }
115 if (canWarnForReactFragment) {
116 var proxy = {};
117 Object.defineProperty(proxy, fragmentKey, {
src/addons/__tests__/ReactFragment-test.js
+21 -2
@@ -73,12 +73,31 @@ describe('ReactFragment', function() {
73 );
74 });
75
76 - it('should warn if accessing any property on a fragment', function() {
76 + it('should warn if passing null to createFragment', function() {
77 spyOn(console, 'warn');
78 ReactFragment.create(null);
79 expect(console.warn.calls.length).toBe(1);
80 expect(console.warn.calls[0].args[0]).toContain(
81 - 'React.addons.createFragment only accepts a single object. Not null'
81 + 'React.addons.createFragment only accepts a single object.'
82 + );
83 + });
84 +
85 + it('should warn if passing an array to createFragment', function() {
86 + spyOn(console, 'warn');
87 + ReactFragment.create([]);
88 + expect(console.warn.calls.length).toBe(1);
89 + expect(console.warn.calls[0].args[0]).toContain(
90 + 'React.addons.createFragment only accepts a single object.'
91 + );
92 + });
93 +
94 + it('should warn if passing a ReactElement to createFragment', function() {
95 + spyOn(console, 'warn');
96 + ReactFragment.create(<div />);
97 + expect(console.warn.calls.length).toBe(1);
98 + expect(console.warn.calls[0].args[0]).toContain(
99 + 'React.addons.createFragment does not accept a ReactElement without a ' +
100 + 'wrapper object.'
101 );
102 });
103