Skip to content

Commit 26d16ab

Browse files
committed
Fail tests if unasserted console calls contain undefined
1 parent f0bed21 commit 26d16ab

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

packages/internal-test-utils/__tests__/ReactInternalTestUtils-test.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2179,7 +2179,17 @@ describe('ReactInternalTestUtils console assertions', () => {
21792179
);
21802180
assertConsoleErrorDev([['Hi', {withoutStack: true}]]);
21812181
});
2182-
expect(message).toMatchInlineSnapshot();
2182+
expect(message).toMatchInlineSnapshot(`
2183+
"assertConsoleErrorDev(expected)
2184+
2185+
Unexpected error(s) recorded.
2186+
2187+
- Expected errors
2188+
+ Received errors
2189+
2190+
Hi
2191+
+ TypeError: Cannot read properties of undefined (reading 'stack') in Foo (at **)"
2192+
`);
21832193
});
21842194
// @gate __DEV__
21852195
it('fails if only error does not contain a stack', () => {

packages/internal-test-utils/consoleMock.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -382,8 +382,9 @@ export function createLogAssertion(
382382

383383
// Main logic to check if log is expected, with the component stack.
384384
if (
385-
normalizedMessage === expectedMessage ||
386-
normalizedMessage.includes(expectedMessage)
385+
expectedMessage !== undefined &&
386+
(normalizedMessage === expectedMessage ||
387+
normalizedMessage.includes(expectedMessage))
387388
) {
388389
if (isLikelyAComponentStack(normalizedMessage)) {
389390
if (expectedWithoutStack === true) {

0 commit comments

Comments
 (0)