Add a test for stateless components returning undefined
We have one for arrays but it is going to become Stack-specific.
Dan Abramov committed
Dec 28, 2016 at 00:14 UTC
fdf0f435c7fab25194eda86ea78d058543862897
1 file changed
+14
src/renderers/shared/shared/__tests__/ReactStatelessComponent-test.js
+14
@@ -138,6 +138,20 @@ describe('ReactStatelessComponent', () => {
138
);
139
});
140
141
+ it('should warn when stateless component returns undefined', () => {
142
+ spyOn(console, 'error');
143
+ function NotAComponent() {
144
+ }
145
+ expect(function() {
146
+ ReactTestUtils.renderIntoDocument(<div><NotAComponent /></div>);
147
+ }).toThrow();
148
+ expectDev(console.error.calls.count()).toBe(1);
149
+ expectDev(console.error.calls.argsFor(0)[0]).toContain(
150
+ 'NotAComponent(...): A valid React element (or null) must be returned. ' +
151
+ 'You may have returned undefined, an array or some other invalid object.'
152
+ );
153
+ });
154
+
155
it('should throw on string refs in pure functions', () => {
156
function Child() {
157
return <div ref="me" />;