mirror of
https://github.com/zebrajr/react.git
synced 2025-12-06 12:20:20 +01:00
Fail tests if unasserted console calls contain undefined (#34191)
This commit is contained in:
parent
0032b2a3ee
commit
9433fe357a
|
|
@ -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(() => {
|
||||
|
|
|
|||
|
|
@ -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 ||
|
||||
normalizedMessage.includes(expectedMessage))
|
||||
) {
|
||||
if (isLikelyAComponentStack(normalizedMessage)) {
|
||||
if (expectedWithoutStack === true) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user