From c555c008b6e13004c57784950eb325ed1d917575 Mon Sep 17 00:00:00 2001 From: Sunil Pai Date: Thu, 14 Feb 2019 17:20:49 +0000 Subject: [PATCH] Include component stack in 'act(...)' warning (#14855) * add a component stack trace to the act() warning * pass tests * nit --- packages/react-dom/src/__tests__/ReactTestUtils-test.js | 7 +++---- packages/react-reconciler/src/ReactFiberScheduler.js | 4 +++- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/packages/react-dom/src/__tests__/ReactTestUtils-test.js b/packages/react-dom/src/__tests__/ReactTestUtils-test.js index 280908c77a0c5..3e35c28dbc20d 100644 --- a/packages/react-dom/src/__tests__/ReactTestUtils-test.js +++ b/packages/react-dom/src/__tests__/ReactTestUtils-test.js @@ -634,10 +634,9 @@ describe('ReactTestUtils', () => { button.dispatchEvent(new MouseEvent('click', {bubbles: true})); }); expect(button.innerHTML).toBe('2'); - expect(() => setValueRef(1)).toWarnDev( - ['An update to App inside a test was not wrapped in act(...).'], - {withoutStack: 1}, - ); + expect(() => setValueRef(1)).toWarnDev([ + 'An update to App inside a test was not wrapped in act(...).', + ]); document.body.removeChild(container); }); diff --git a/packages/react-reconciler/src/ReactFiberScheduler.js b/packages/react-reconciler/src/ReactFiberScheduler.js index c86b66d2b8b38..9fe67f90aa7f8 100644 --- a/packages/react-reconciler/src/ReactFiberScheduler.js +++ b/packages/react-reconciler/src/ReactFiberScheduler.js @@ -1839,8 +1839,10 @@ export function warnIfNotCurrentlyBatchingInDev(fiber: Fiber): void { '});\n' + '/* assert on the output */\n\n' + "This ensures that you're testing the behavior the user would see in the browser." + - ' Learn more at https://fb.me/react-wrap-tests-with-act', + ' Learn more at https://fb.me/react-wrap-tests-with-act' + + '%s', getComponentName(fiber.type), + getStackByFiberInDevAndProd(fiber), ); } }