From fe2ac552f8d5d067d502b30929e1fd6ef51e4766 Mon Sep 17 00:00:00 2001 From: Hendrik Liebau Date: Fri, 3 Mar 2023 18:52:09 +0100 Subject: [PATCH] [Flight] Add test expectation for error digest in prod --- .../__tests__/ReactFlightDOMBrowser-test.js | 29 +++++++++++++++---- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/packages/react-server-dom-webpack/src/__tests__/ReactFlightDOMBrowser-test.js b/packages/react-server-dom-webpack/src/__tests__/ReactFlightDOMBrowser-test.js index 348aba5ee9ac0..f3f4ffbd9f350 100644 --- a/packages/react-server-dom-webpack/src/__tests__/ReactFlightDOMBrowser-test.js +++ b/packages/react-server-dom-webpack/src/__tests__/ReactFlightDOMBrowser-test.js @@ -875,7 +875,11 @@ describe('ReactFlightDOMBrowser', () => { async callServer(ref, args) { const fn = requireServerRef(ref); return ReactServerDOMReader.createFromReadableStream( - ReactServerDOMWriter.renderToReadableStream(fn.apply(null, args)), + ReactServerDOMWriter.renderToReadableStream( + fn.apply(null, args), + null, + {onError: error => 'test-error-digest'}, + ), ); }, }); @@ -890,9 +894,24 @@ describe('ReactFlightDOMBrowser', () => { root.render(); }); - const expectedError = new Error('Error for test'); - spyOnDevAndProd(console, 'error').mockImplementation(() => {}); - await expect(actionProxy('test')).rejects.toThrow(expectedError); - expect(console.error.mock.calls).toEqual([[expectedError]]); + if (__DEV__) { + await expect(actionProxy('test')).rejects.toThrow('Error for test'); + } else { + let thrownError; + + try { + await actionProxy('test'); + } catch (error) { + thrownError = error; + } + + expect(thrownError).toEqual( + new Error( + 'An error occurred in the Server Components render. The specific message is omitted in production builds to avoid leaking sensitive details. A digest property is included on this error instance which may provide additional details about the nature of the error.', + ), + ); + + expect(thrownError.digest).toBe('test-error-digest'); + } }); });