Skip to content

Commit

Permalink
[TestUtils.act] fix return result checking (#14758)
Browse files Browse the repository at this point in the history
* fix .act return value testing when result === null

* nit
  • Loading branch information
Sunil Pai authored Feb 5, 2019
1 parent 267ed98 commit d1326f4
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 3 deletions.
6 changes: 6 additions & 0 deletions packages/react-dom/src/__tests__/ReactTestUtils-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -665,6 +665,12 @@ describe('ReactTestUtils', () => {
});

it('warns if you return a value inside act', () => {
expect(() => act(() => null)).toWarnDev(
[
'The callback passed to ReactTestUtils.act(...) function must not return anything.',
],
{withoutStack: true},
);
expect(() => act(() => 123)).toWarnDev(
[
'The callback passed to ReactTestUtils.act(...) function must not return anything.',
Expand Down
2 changes: 1 addition & 1 deletion packages/react-dom/src/test-utils/ReactTestUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ const ReactTestUtils = {
if (__DEV__) {
if (result !== undefined) {
let addendum;
if (typeof result.then === 'function') {
if (result !== null && typeof result.then === 'function') {
addendum =
'\n\nIt looks like you wrote ReactTestUtils.act(async () => ...), ' +
'or returned a Promise from the callback passed to it. ' +
Expand Down
2 changes: 1 addition & 1 deletion packages/react-noop-renderer/src/createReactNoop.js
Original file line number Diff line number Diff line change
Expand Up @@ -878,7 +878,7 @@ function createReactNoop(reconciler: Function, useMutation: boolean) {
if (__DEV__) {
if (result !== undefined) {
let addendum;
if (typeof result.then === 'function') {
if (result !== null && typeof result.then === 'function') {
addendum =
"\n\nIt looks like you wrote ReactNoop.act(async () => ...) or returned a Promise from it's callback. " +
'Putting asynchronous logic inside ReactNoop.act(...) is not supported.\n';
Expand Down
2 changes: 1 addition & 1 deletion packages/react-test-renderer/src/ReactTestRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,7 @@ const ReactTestRendererFiber = {
if (__DEV__) {
if (result !== undefined) {
let addendum;
if (typeof result.then === 'function') {
if (result !== null && typeof result.then === 'function') {
addendum =
"\n\nIt looks like you wrote TestRenderer.act(async () => ...) or returned a Promise from it's callback. " +
'Putting asynchronous logic inside TestRenderer.act(...) is not supported.\n';
Expand Down

0 comments on commit d1326f4

Please sign in to comment.