diff --git a/src/__tests__/old-act.js b/src/__tests__/old-act.js index fcd531b4..0116ba7c 100644 --- a/src/__tests__/old-act.js +++ b/src/__tests__/old-act.js @@ -32,18 +32,15 @@ test('async act works even when the act is an old one', async () => { console.error('sigil') }) expect(console.error.mock.calls).toMatchInlineSnapshot(` - Array [ - Array [ - "sigil", - ], - Array [ - "It looks like you're using a version of react-dom that supports the \\"act\\" function, but not an awaitable version of \\"act\\" which you will need. Please upgrade to at least react-dom@16.9.0 to remove this warning.", - ], - Array [ - "sigil", - ], - ] - `) + Array [ + Array [ + "It looks like you're using a version of react-dom that supports the \\"act\\" function, but not an awaitable version of \\"act\\" which you will need. Please upgrade to at least react-dom@16.9.0 to remove this warning.", + ], + Array [ + "sigil", + ], + ] + `) expect(callback).toHaveBeenCalledTimes(1) // and it doesn't warn you twice @@ -98,4 +95,28 @@ test('async act recovers from sync errors', async () => { `) }) +test('async act handles values that are not strings', async () => { + try { + await asyncAct(async () => { + console.error({message: 'some message'}) + await null + }) + } catch (err) { + console.error('call console.error') + } + expect(console.error).toHaveBeenCalledTimes(2) + expect(console.error.mock.calls).toMatchInlineSnapshot(` + Array [ + Array [ + Object { + "message": "some message", + }, + ], + Array [ + "It looks like you're using a version of react-dom that supports the \\"act\\" function, but not an awaitable version of \\"act\\" which you will need. Please upgrade to at least react-dom@16.9.0 to remove this warning.", + ], + ] + `) +}) + /* eslint no-console:0 */ diff --git a/src/act-compat.js b/src/act-compat.js index dd5f1d96..3c0c2395 100644 --- a/src/act-compat.js +++ b/src/act-compat.js @@ -28,19 +28,21 @@ function asyncAct(cb) { console.error = function error(...args) { /* if console.error fired *with that specific message* */ /* istanbul ignore next */ - if ( - args[0].indexOf( - 'Warning: Do not await the result of calling ReactTestUtils.act', - ) === 0 - ) { - // v16.8.6 - isAsyncActSupported = false - } else if ( - args[0].indexOf( - 'Warning: The callback passed to ReactTestUtils.act(...) function must not return anything', - ) === 0 - ) { - // no-op + if (typeof args[0] === 'string') { + if ( + args[0].indexOf( + 'Warning: Do not await the result of calling ReactTestUtils.act', + ) === 0 + ) { + // v16.8.6 + isAsyncActSupported = false + } else if ( + args[0].indexOf( + 'Warning: The callback passed to ReactTestUtils.act(...) function must not return anything', + ) === 0 + ) { + // no-op + } } else { originalConsoleError.apply(console, args) }