Fix SSR integration test swallowing lack of expected error (#10331)
* Don't catch the assertion about missing errors Previously, even if an error was not thrown, the assertion about this was ignored. This fix exposes two failing cases in new SSR that weren't failing in Stack. * Add child context validation to new SSR This fixes the error cases that were silently failing before but are now exposed.
Dan Abramov committed
Jul 31, 2017 at 17:57 UTC
67347a64590a1b47fea24b1e695d985b35ef5217
2 files changed
+31
-11
src/renderers/dom/shared/__tests__/ReactDOMServerIntegration-test.js
+4
-5
@@ -229,11 +229,10 @@ function itClientRenders(desc, testFn) {
229
230
function itThrows(desc, testFn) {
231
it(`throws ${desc}`, () => {
232
- return testFn()
233
- .then(() =>
234
- expect(false).toBe('The promise resolved and should not have.'),
235
- )
236
- .catch(() => {});
232
+ return testFn().then(
233
+ () => expect(false).toBe('The promise resolved and should not have.'),
234
+ () => {},
235
+ );
236
});
237
}
238
src/renderers/shared/server/ReactPartialRenderer.js
+27
-6
@@ -50,9 +50,7 @@ if (__DEV__) {
50
var describeStackFrame = function(element): string {
51
var source = element._source;
52
var type = element.type;
53
- var name = typeof type === 'string'
54
- ? type
55
- : typeof type === 'function' ? type.displayName || type.name : null;
53
+ var name = getComponentName(type);
54
var ownerName = null;
55
return describeComponentFrame(name, source, ownerName);
56
};
@@ -105,6 +103,12 @@ var newlineEatingTags = {
103
textarea: true,
104
};
105
106
+function getComponentName(type) {
107
+ return typeof type === 'string'
108
+ ? type
109
+ : typeof type === 'function' ? type.displayName || type.name : null;
110
+}
111
+
112
// We accept any tag to be rendered but since this gets injected into arbitrary
113
// HTML, we want to make sure that it's a safe tag.
114
// http://www.w3.org/TR/REC-xml/#NT-Name
@@ -162,8 +166,7 @@ function warnNoop(
166
'This is a no-op.\n\nPlease check the code for the %s component.',
167
callerName,
168
callerName,
165
- (constructor && (constructor.displayName || constructor.name)) ||
166
- 'ReactClass',
169
+ (constructor && getComponentName(constructor)) || 'ReactClass',
170
);
171
}
172
}
@@ -403,7 +406,25 @@ function resolve(child, context) {
406
}
407
}
408
406
- var childContext = inst.getChildContext && inst.getChildContext();
409
+ var childContext;
410
+ if (typeof inst.getChildContext === 'function') {
411
+ var childContextTypes = Component.childContextTypes;
412
+ invariant(
413
+ typeof childContextTypes === 'object',
414
+ '%s.getChildContext(): childContextTypes must be defined in order to ' +
415
+ 'use getChildContext().',
416
+ getComponentName(Component) || 'Unknown',
417
+ );
418
+ childContext = inst.getChildContext();
419
+ for (let contextKey in childContext) {
420
+ invariant(
421
+ contextKey in childContextTypes,
422
+ '%s.getChildContext(): key "%s" is not defined in childContextTypes.',
423
+ getComponentName(Component) || 'Unknown',
424
+ contextKey,
425
+ );
426
+ }
427
+ }
428
if (childContext) {
429
context = Object.assign({}, context, childContext);
430
}