[TestUtils.act] fix return result checking (#14758)
* fix .act return value testing when result === null * nit
Sunil Pai committed
Feb 5, 2019 at 17:34 UTC
d1326f466a24f2b9e09115ed1a3ddd9de2ad2e06
4 files changed
+9
-3
packages/react-dom/src/__tests__/ReactTestUtils-test.js
+6
@@ -665,6 +665,12 @@ describe('ReactTestUtils', () => {
665
});
666
667
it('warns if you return a value inside act', () => {
668
+ expect(() => act(() => null)).toWarnDev(
669
+ [
670
+ 'The callback passed to ReactTestUtils.act(...) function must not return anything.',
671
+ ],
672
+ {withoutStack: true},
673
+ );
674
expect(() => act(() => 123)).toWarnDev(
675
[
676
'The callback passed to ReactTestUtils.act(...) function must not return anything.',
packages/react-dom/src/test-utils/ReactTestUtils.js
+1
-1
@@ -397,7 +397,7 @@ const ReactTestUtils = {
397
if (__DEV__) {
398
if (result !== undefined) {
399
let addendum;
400
- if (typeof result.then === 'function') {
400
+ if (result !== null && typeof result.then === 'function') {
401
addendum =
402
'\n\nIt looks like you wrote ReactTestUtils.act(async () => ...), ' +
403
'or returned a Promise from the callback passed to it. ' +
packages/react-noop-renderer/src/createReactNoop.js
+1
-1
@@ -878,7 +878,7 @@ function createReactNoop(reconciler: Function, useMutation: boolean) {
878
if (__DEV__) {
879
if (result !== undefined) {
880
let addendum;
881
- if (typeof result.then === 'function') {
881
+ if (result !== null && typeof result.then === 'function') {
882
addendum =
883
"\n\nIt looks like you wrote ReactNoop.act(async () => ...) or returned a Promise from it's callback. " +
884
'Putting asynchronous logic inside ReactNoop.act(...) is not supported.\n';
packages/react-test-renderer/src/ReactTestRenderer.js
+1
-1
@@ -571,7 +571,7 @@ const ReactTestRendererFiber = {
571
if (__DEV__) {
572
if (result !== undefined) {
573
let addendum;
574
- if (typeof result.then === 'function') {
574
+ if (result !== null && typeof result.then === 'function') {
575
addendum =
576
"\n\nIt looks like you wrote TestRenderer.act(async () => ...) or returned a Promise from it's callback. " +
577
'Putting asynchronous logic inside TestRenderer.act(...) is not supported.\n';