Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

console test utils fix: match entire string, not just first letter #28855

Merged
Merged
Changes from 1 commit
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
Next Next commit
console test utils fix: match entire string
Fixes issue where if the first letter of the expected string appeared
anywhere in actual message, the assertion would pass, leading to
false negatives. We should check the entire expected string.
  • Loading branch information
acdlite committed Apr 17, 2024
commit ccf7cc82fe46165bfe87c9b17755f74c50cc6157
Original file line number Diff line number Diff line change
@@ -2129,6 +2129,28 @@ describe('ReactInternalTestUtils console assertions', () => {
`);
});

// @gate __DEV__
it('regression: checks entire string, not just the first letter', async () => {
const message = expectToThrowFailure(() => {
console.error('Message that happens to contain a "T"\n in div');

assertConsoleErrorDev([
'This is a complete different message that happens to start with "T"',
acdlite marked this conversation as resolved.
Show resolved Hide resolved
]);
});
expect(message).toMatchInlineSnapshot(`
"assertConsoleErrorDev(expected)

Unexpected error(s) recorded.

- Expected errors
+ Received errors

- This is a complete different message that happens to start with "T"
+ Message that happens to contain a "T" <component stack>"
`);
});

describe('global withoutStack', () => {
// @gate __DEV__
it('passes if errors without stack explicitly opt out', () => {
2 changes: 1 addition & 1 deletion packages/internal-test-utils/consoleMock.js
Original file line number Diff line number Diff line change
@@ -386,7 +386,7 @@ export function createLogAssertion(
expectedWithoutStack = expectedMessageOrArray[1].withoutStack;
} else if (typeof expectedMessageOrArray === 'string') {
// Should be in the form assert(['log']) or assert(['log'], {withoutStack: true})
expectedMessage = replaceComponentStack(expectedMessageOrArray[0]);
expectedMessage = replaceComponentStack(expectedMessageOrArray);
if (consoleMethod === 'log') {
expectedWithoutStack = true;
} else {