[TestUtils.act] fix return result checking (#14758)

* fix .act return value testing when result === null

* nit
This commit is contained in:
Sunil Pai 2019-02-05 17:34:21 +00:00 committed by GitHub
parent 267ed98146
commit d1326f466a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 9 additions and 3 deletions

View File

@ -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.',

View File

@ -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. ' +

View File

@ -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';

View File

@ -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';