Fix suspenseCallback type warning, add a test (#16194)

This commit is contained in:
Benoit Girard
2019-07-24 18:32:00 +01:00
committed by Dominic Gannaway
parent 7ad221126f
commit 144dba1a11
2 changed files with 27 additions and 1 deletions
+3 -1
View File
@@ -1330,7 +1330,9 @@ function commitSuspenseComponent(finishedWork: Fiber) {
suspenseCallback(new Set(thenables));
}
} else if (__DEV__) {
warning(false, 'Unexpected type for suspenseCallback.');
if (suspenseCallback !== undefined) {
warning(false, 'Unexpected type for suspenseCallback.');
}
}
}
}
@@ -50,6 +50,30 @@ describe('ReactSuspense', () => {
return {promise, resolveRef, PromiseComp};
}
it('check type', () => {
const {PromiseComp} = createThenable();
const elementBadType = (
<React.Suspense suspenseCallback={1} fallback={'Waiting'}>
<PromiseComp />
</React.Suspense>
);
ReactNoop.render(elementBadType);
expect(() => Scheduler.unstable_flushAll()).toWarnDev([
'Warning: Unexpected type for suspenseCallback.',
]);
const elementMissingCallback = (
<React.Suspense fallback={'Waiting'}>
<PromiseComp />
</React.Suspense>
);
ReactNoop.render(elementMissingCallback);
expect(() => Scheduler.unstable_flushAll()).toWarnDev([]);
});
it('1 then 0 suspense callback', () => {
const {promise, resolveRef, PromiseComp} = createThenable();