mirror of
https://github.com/hanzoai/react.git
synced 2026-09-24 17:02:27 +00:00
Fix assertConsoleErrorDev on message mismatch with withoutStack: true (#29198)
## Summary
```js
assertConsoleErrorDev([
['Hello', {withoutStack: true}]
])
```
now errors with a helpful diff message if the message mismatched. See
first commit for previous behavior.
## How did you test this change?
- `yarn test --watch
packages/internal-test-utils/__tests__/ReactInternalTestUtils-test.js`
This commit is contained in:
committed by
GitHub
parent
4f21085fce
commit
76405a2fda
@@ -2417,6 +2417,32 @@ describe('ReactInternalTestUtils console assertions', () => {
|
||||
If all errors should include the component stack, you may need to remove {withoutStack: true} from the assertConsoleErrorDev call."
|
||||
`);
|
||||
});
|
||||
|
||||
// @gate __DEV__
|
||||
it('fails with a helpful error message if the expected error message mismatches', () => {
|
||||
const message = expectToThrowFailure(() => {
|
||||
console.error('Bye\n in div');
|
||||
assertConsoleErrorDev([
|
||||
[
|
||||
'Hello',
|
||||
{
|
||||
withoutStack: true,
|
||||
},
|
||||
],
|
||||
]);
|
||||
});
|
||||
expect(message).toMatchInlineSnapshot(`
|
||||
"assertConsoleErrorDev(expected)
|
||||
|
||||
Unexpected error(s) recorded.
|
||||
|
||||
- Expected errors
|
||||
+ Received errors
|
||||
|
||||
- Hello
|
||||
+ Bye <component stack>"
|
||||
`);
|
||||
});
|
||||
});
|
||||
|
||||
// @gate __DEV__
|
||||
|
||||
@@ -464,7 +464,12 @@ export function createLogAssertion(
|
||||
function printDiff() {
|
||||
return `${diff(
|
||||
expectedMessages
|
||||
.map(message => message.replace('\n', ' '))
|
||||
.map(messageOrTuple => {
|
||||
const message = Array.isArray(messageOrTuple)
|
||||
? messageOrTuple[0]
|
||||
: messageOrTuple;
|
||||
return message.replace('\n', ' ');
|
||||
})
|
||||
.join('\n'),
|
||||
receivedLogs.map(message => message.replace('\n', ' ')).join('\n'),
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user