Skip to content

Commit d1326f4

Browse files
author
Sunil Pai
authored
[TestUtils.act] fix return result checking (#14758)
* fix .act return value testing when result === null * nit
1 parent 267ed98 commit d1326f4

File tree

4 files changed

+9
-3
lines changed

4 files changed

+9
-3
lines changed

packages/react-dom/src/__tests__/ReactTestUtils-test.js

+6
Original file line numberDiff line numberDiff line change
@@ -665,6 +665,12 @@ describe('ReactTestUtils', () => {
665665
});
666666

667667
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+
);
668674
expect(() => act(() => 123)).toWarnDev(
669675
[
670676
'The callback passed to ReactTestUtils.act(...) function must not return anything.',

packages/react-dom/src/test-utils/ReactTestUtils.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,7 @@ const ReactTestUtils = {
397397
if (__DEV__) {
398398
if (result !== undefined) {
399399
let addendum;
400-
if (typeof result.then === 'function') {
400+
if (result !== null && typeof result.then === 'function') {
401401
addendum =
402402
'\n\nIt looks like you wrote ReactTestUtils.act(async () => ...), ' +
403403
'or returned a Promise from the callback passed to it. ' +

packages/react-noop-renderer/src/createReactNoop.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -878,7 +878,7 @@ function createReactNoop(reconciler: Function, useMutation: boolean) {
878878
if (__DEV__) {
879879
if (result !== undefined) {
880880
let addendum;
881-
if (typeof result.then === 'function') {
881+
if (result !== null && typeof result.then === 'function') {
882882
addendum =
883883
"\n\nIt looks like you wrote ReactNoop.act(async () => ...) or returned a Promise from it's callback. " +
884884
'Putting asynchronous logic inside ReactNoop.act(...) is not supported.\n';

packages/react-test-renderer/src/ReactTestRenderer.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -571,7 +571,7 @@ const ReactTestRendererFiber = {
571571
if (__DEV__) {
572572
if (result !== undefined) {
573573
let addendum;
574-
if (typeof result.then === 'function') {
574+
if (result !== null && typeof result.then === 'function') {
575575
addendum =
576576
"\n\nIt looks like you wrote TestRenderer.act(async () => ...) or returned a Promise from it's callback. " +
577577
'Putting asynchronous logic inside TestRenderer.act(...) is not supported.\n';

0 commit comments

Comments
 (0)