mirror of
https://github.com/hanzoai/react.git
synced 2026-09-24 17:02:27 +00:00
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.
This commit is contained in:
@@ -229,11 +229,10 @@ function itClientRenders(desc, testFn) {
|
||||
|
||||
function itThrows(desc, testFn) {
|
||||
it(`throws ${desc}`, () => {
|
||||
return testFn()
|
||||
.then(() =>
|
||||
expect(false).toBe('The promise resolved and should not have.'),
|
||||
)
|
||||
.catch(() => {});
|
||||
return testFn().then(
|
||||
() => expect(false).toBe('The promise resolved and should not have.'),
|
||||
() => {},
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -50,9 +50,7 @@ if (__DEV__) {
|
||||
var describeStackFrame = function(element): string {
|
||||
var source = element._source;
|
||||
var type = element.type;
|
||||
var name = typeof type === 'string'
|
||||
? type
|
||||
: typeof type === 'function' ? type.displayName || type.name : null;
|
||||
var name = getComponentName(type);
|
||||
var ownerName = null;
|
||||
return describeComponentFrame(name, source, ownerName);
|
||||
};
|
||||
@@ -105,6 +103,12 @@ var newlineEatingTags = {
|
||||
textarea: true,
|
||||
};
|
||||
|
||||
function getComponentName(type) {
|
||||
return typeof type === 'string'
|
||||
? type
|
||||
: typeof type === 'function' ? type.displayName || type.name : null;
|
||||
}
|
||||
|
||||
// We accept any tag to be rendered but since this gets injected into arbitrary
|
||||
// HTML, we want to make sure that it's a safe tag.
|
||||
// http://www.w3.org/TR/REC-xml/#NT-Name
|
||||
@@ -162,8 +166,7 @@ function warnNoop(
|
||||
'This is a no-op.\n\nPlease check the code for the %s component.',
|
||||
callerName,
|
||||
callerName,
|
||||
(constructor && (constructor.displayName || constructor.name)) ||
|
||||
'ReactClass',
|
||||
(constructor && getComponentName(constructor)) || 'ReactClass',
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -403,7 +406,25 @@ function resolve(child, context) {
|
||||
}
|
||||
}
|
||||
|
||||
var childContext = inst.getChildContext && inst.getChildContext();
|
||||
var childContext;
|
||||
if (typeof inst.getChildContext === 'function') {
|
||||
var childContextTypes = Component.childContextTypes;
|
||||
invariant(
|
||||
typeof childContextTypes === 'object',
|
||||
'%s.getChildContext(): childContextTypes must be defined in order to ' +
|
||||
'use getChildContext().',
|
||||
getComponentName(Component) || 'Unknown',
|
||||
);
|
||||
childContext = inst.getChildContext();
|
||||
for (let contextKey in childContext) {
|
||||
invariant(
|
||||
contextKey in childContextTypes,
|
||||
'%s.getChildContext(): key "%s" is not defined in childContextTypes.',
|
||||
getComponentName(Component) || 'Unknown',
|
||||
contextKey,
|
||||
);
|
||||
}
|
||||
}
|
||||
if (childContext) {
|
||||
context = Object.assign({}, context, childContext);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user