Skip to content

Commit

Permalink
[Flight] Add test expectation for error digest in prod
Browse files Browse the repository at this point in the history
  • Loading branch information
unstubbable committed Mar 3, 2023
1 parent 9e1d958 commit fe2ac55
Showing 1 changed file with 24 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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'},
),
);
},
});
Expand All @@ -890,9 +894,24 @@ describe('ReactFlightDOMBrowser', () => {
root.render(<App />);
});

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');
}
});
});

0 comments on commit fe2ac55

Please sign in to comment.