Skip to content

Commit

Permalink
[tests] Remove to*Dev matchers (#31989)
Browse files Browse the repository at this point in the history
Based off: #31988

<img width="741" alt="Screenshot 2025-01-06 at 12 52 08 AM"
src="https://github.com/user-attachments/assets/29b159ca-66d4-441f-8817-dd2db66d1edb"
/>

it is done
  • Loading branch information
rickhanlonii authored Jan 7, 2025
1 parent f892dab commit a160102
Show file tree
Hide file tree
Showing 11 changed files with 149 additions and 1,097 deletions.
1 change: 0 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,6 @@ module.exports = {
ERROR,
{isProductionUserAppCode: true},
],
'react-internal/no-to-warn-dev-within-to-throw': ERROR,
'react-internal/warning-args': ERROR,
'react-internal/no-production-logging': ERROR,
},
Expand Down
158 changes: 75 additions & 83 deletions packages/internal-test-utils/__tests__/ReactInternalTestUtils-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
const React = require('react');
const stripAnsi = require('strip-ansi');
const {startTransition, useDeferredValue} = React;
const chalk = require('chalk');
const ReactNoop = require('react-noop-renderer');
const {
waitFor,
Expand All @@ -25,7 +24,7 @@ const {
const act = require('internal-test-utils').act;
const Scheduler = require('scheduler/unstable_mock');
const {
flushAllUnexpectedConsoleCalls,
assertConsoleLogsCleared,
resetAllUnexpectedConsoleCalls,
patchConsoleMethods,
} = require('../consoleMock');
Expand Down Expand Up @@ -205,16 +204,17 @@ describe('ReactInternalTestUtils console mocks', () => {
it('should fail if not asserted', () => {
expect(() => {
console.log('hit');
flushAllUnexpectedConsoleCalls();
}).toThrow(`Expected test not to call ${chalk.bold('console.log()')}.`);
assertConsoleLogsCleared();
}).toThrow(`console.log was called without assertConsoleLogDev`);
});

// @gate __DEV__
it('should not fail if mocked with spyOnDev', () => {
spyOnDev(console, 'log').mockImplementation(() => {});
expect(() => {
console.log('hit');
flushAllUnexpectedConsoleCalls();
if (__DEV__) {
console.log('hit');
}
assertConsoleLogsCleared();
}).not.toThrow();
});

Expand All @@ -223,41 +223,34 @@ describe('ReactInternalTestUtils console mocks', () => {
spyOnProd(console, 'log').mockImplementation(() => {});
expect(() => {
console.log('hit');
flushAllUnexpectedConsoleCalls();
assertConsoleLogsCleared();
}).not.toThrow();
});

it('should not fail if mocked with spyOnDevAndProd', () => {
spyOnDevAndProd(console, 'log').mockImplementation(() => {});
expect(() => {
console.log('hit');
flushAllUnexpectedConsoleCalls();
assertConsoleLogsCleared();
}).not.toThrow();
});

// @gate __DEV__
it('should not fail with toLogDev', () => {
expect(() => {
console.log('hit');
flushAllUnexpectedConsoleCalls();
}).toLogDev(['hit']);
});
});

describe('console.warn', () => {
it('should fail if not asserted', () => {
expect(() => {
console.warn('hit');
flushAllUnexpectedConsoleCalls();
}).toThrow(`Expected test not to call ${chalk.bold('console.warn()')}.`);
assertConsoleLogsCleared();
}).toThrow('console.warn was called without assertConsoleWarnDev');
});

// @gate __DEV__
it('should not fail if mocked with spyOnDev', () => {
spyOnDev(console, 'warn').mockImplementation(() => {});
expect(() => {
console.warn('hit');
flushAllUnexpectedConsoleCalls();
if (__DEV__) {
console.warn('hit');
}
assertConsoleLogsCleared();
}).not.toThrow();
});

Expand All @@ -266,41 +259,34 @@ describe('ReactInternalTestUtils console mocks', () => {
spyOnProd(console, 'warn').mockImplementation(() => {});
expect(() => {
console.warn('hit');
flushAllUnexpectedConsoleCalls();
assertConsoleLogsCleared();
}).not.toThrow();
});

it('should not fail if mocked with spyOnDevAndProd', () => {
spyOnDevAndProd(console, 'warn').mockImplementation(() => {});
expect(() => {
console.warn('hit');
flushAllUnexpectedConsoleCalls();
assertConsoleLogsCleared();
}).not.toThrow();
});

// @gate __DEV__
it('should not fail with toWarnDev', () => {
expect(() => {
console.warn('hit');
flushAllUnexpectedConsoleCalls();
}).toWarnDev(['hit'], {withoutStack: true});
});
});

describe('console.error', () => {
it('should fail if console.error is not asserted', () => {
expect(() => {
console.error('hit');
flushAllUnexpectedConsoleCalls();
}).toThrow(`Expected test not to call ${chalk.bold('console.error()')}.`);
assertConsoleLogsCleared();
}).toThrow('console.error was called without assertConsoleErrorDev');
});

// @gate __DEV__
it('should not fail if mocked with spyOnDev', () => {
spyOnDev(console, 'error').mockImplementation(() => {});
expect(() => {
console.error('hit');
flushAllUnexpectedConsoleCalls();
if (__DEV__) {
console.error('hit');
}
assertConsoleLogsCleared();
}).not.toThrow();
});

Expand All @@ -309,25 +295,17 @@ describe('ReactInternalTestUtils console mocks', () => {
spyOnProd(console, 'error').mockImplementation(() => {});
expect(() => {
console.error('hit');
flushAllUnexpectedConsoleCalls();
assertConsoleLogsCleared();
}).not.toThrow();
});

it('should not fail if mocked with spyOnDevAndProd', () => {
spyOnDevAndProd(console, 'error').mockImplementation(() => {});
expect(() => {
console.error('hit');
flushAllUnexpectedConsoleCalls();
assertConsoleLogsCleared();
}).not.toThrow();
});

// @gate __DEV__
it('should not fail with toErrorDev', () => {
expect(() => {
console.error('hit');
flushAllUnexpectedConsoleCalls();
}).toErrorDev(['hit'], {withoutStack: true});
});
});
});

Expand Down Expand Up @@ -361,17 +339,19 @@ describe('ReactInternalTestUtils console assertions', () => {
});

describe('assertConsoleLogDev', () => {
// @gate __DEV__
it('passes for a single log', () => {
console.log('Hello');
if (__DEV__) {
console.log('Hello');
}
assertConsoleLogDev(['Hello']);
});

// @gate __DEV__
it('passes for multiple logs', () => {
console.log('Hello');
console.log('Good day');
console.log('Bye');
if (__DEV__) {
console.log('Hello');
console.log('Good day');
console.log('Bye');
}
assertConsoleLogDev(['Hello', 'Good day', 'Bye']);
});

Expand Down Expand Up @@ -906,17 +886,19 @@ describe('ReactInternalTestUtils console assertions', () => {
});

describe('assertConsoleWarnDev', () => {
// @gate __DEV__
it('passes if an warning contains a stack', () => {
console.warn('Hello\n in div');
if (__DEV__) {
console.warn('Hello\n in div');
}
assertConsoleWarnDev(['Hello']);
});

// @gate __DEV__
it('passes if all warnings contain a stack', () => {
console.warn('Hello\n in div');
console.warn('Good day\n in div');
console.warn('Bye\n in div');
if (__DEV__) {
console.warn('Hello\n in div');
console.warn('Good day\n in div');
console.warn('Bye\n in div');
}
assertConsoleWarnDev(['Hello', 'Good day', 'Bye']);
});

Expand Down Expand Up @@ -1353,14 +1335,17 @@ describe('ReactInternalTestUtils console assertions', () => {
});

describe('global withoutStack', () => {
// @gate __DEV__
it('passes if warnings without stack explicitly opt out', () => {
console.warn('Hello');
if (__DEV__) {
console.warn('Hello');
}
assertConsoleWarnDev(['Hello'], {withoutStack: true});

console.warn('Hello');
console.warn('Good day');
console.warn('Bye');
if (__DEV__) {
console.warn('Hello');
console.warn('Good day');
console.warn('Bye');
}

assertConsoleWarnDev(['Hello', 'Good day', 'Bye'], {
withoutStack: true,
Expand Down Expand Up @@ -1460,11 +1445,12 @@ describe('ReactInternalTestUtils console assertions', () => {
});
});
describe('local withoutStack', () => {
// @gate __DEV__
it('passes when expected withoutStack logs matches the actual logs', () => {
console.warn('Hello\n in div');
console.warn('Good day');
console.warn('Bye\n in div');
if (__DEV__) {
console.warn('Hello\n in div');
console.warn('Good day');
console.warn('Bye\n in div');
}
assertConsoleWarnDev([
'Hello',
['Good day', {withoutStack: true}],
Expand Down Expand Up @@ -1981,17 +1967,19 @@ describe('ReactInternalTestUtils console assertions', () => {
});

describe('assertConsoleErrorDev', () => {
// @gate __DEV__
it('passes if an error contains a stack', () => {
console.error('Hello\n in div');
if (__DEV__) {
console.error('Hello\n in div');
}
assertConsoleErrorDev(['Hello']);
});

// @gate __DEV__
it('passes if all errors contain a stack', () => {
console.error('Hello\n in div');
console.error('Good day\n in div');
console.error('Bye\n in div');
if (__DEV__) {
console.error('Hello\n in div');
console.error('Good day\n in div');
console.error('Bye\n in div');
}
assertConsoleErrorDev(['Hello', 'Good day', 'Bye']);
});

Expand Down Expand Up @@ -2446,14 +2434,17 @@ describe('ReactInternalTestUtils console assertions', () => {
});

describe('global withoutStack', () => {
// @gate __DEV__
it('passes if errors without stack explicitly opt out', () => {
console.error('Hello');
if (__DEV__) {
console.error('Hello');
}
assertConsoleErrorDev(['Hello'], {withoutStack: true});

console.error('Hello');
console.error('Good day');
console.error('Bye');
if (__DEV__) {
console.error('Hello');
console.error('Good day');
console.error('Bye');
}

assertConsoleErrorDev(['Hello', 'Good day', 'Bye'], {
withoutStack: true,
Expand Down Expand Up @@ -2553,11 +2544,12 @@ describe('ReactInternalTestUtils console assertions', () => {
});
});
describe('local withoutStack', () => {
// @gate __DEV__
it('passes when expected withoutStack logs matches the actual logs', () => {
console.error('Hello\n in div');
console.error('Good day');
console.error('Bye\n in div');
if (__DEV__) {
console.error('Hello\n in div');
console.error('Good day');
console.error('Bye\n in div');
}
assertConsoleErrorDev([
'Hello',
['Good day', {withoutStack: true}],
Expand Down
Loading

0 comments on commit a160102

Please sign in to comment.