Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2169,6 +2169,29 @@ describe('ReactInternalTestUtils console assertions', () => {
+ Bye in div (at **)"
`);
});

// @gate __DEV__
it('fails if last received error containing "undefined" is not included', () => {
const message = expectToThrowFailure(() => {
console.error('Hi');
console.error(
"TypeError: Cannot read properties of undefined (reading 'stack')\n" +
' in Foo (at **)'
);
assertConsoleErrorDev([['Hi', {withoutStack: true}]]);
});
expect(message).toMatchInlineSnapshot(`
"assertConsoleErrorDev(expected)

Unexpected error(s) recorded.

- Expected errors
+ Received errors

Hi
+ TypeError: Cannot read properties of undefined (reading 'stack') in Foo (at **)"
`);
});
// @gate __DEV__
it('fails if only error does not contain a stack', () => {
const message = expectToThrowFailure(() => {
Expand Down
5 changes: 3 additions & 2 deletions packages/internal-test-utils/consoleMock.js
Original file line number Diff line number Diff line change
Expand Up @@ -382,8 +382,9 @@ export function createLogAssertion(

// Main logic to check if log is expected, with the component stack.
if (
normalizedMessage === expectedMessage ||
normalizedMessage.includes(expectedMessage)
typeof expectedMessage === 'string' &&
(normalizedMessage === expectedMessage ||
Comment on lines +385 to +386
Copy link
Collaborator Author

@eps1lon eps1lon Aug 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This forbids console.error('undefined') and assertConsoleErrorDev([undefined]) but that doesn't seem like a valid scenario anyway.

normalizedMessage.includes(expectedMessage))
) {
if (isLikelyAComponentStack(normalizedMessage)) {
if (expectedWithoutStack === true) {
Expand Down
Loading