MCPcopy
hub / github.com/facebook/react / assertConsoleLogsCleared

Function assertConsoleLogsCleared

packages/internal-test-utils/consoleMock.js:101–146  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

99}
100
101export function assertConsoleLogsCleared() {
102 const logs = clearLogs();
103 const warnings = clearWarnings();
104 const errors = clearErrors();
105
106 if (logs.length > 0 || errors.length > 0 || warnings.length > 0) {
107 let message = `${chalk.dim('asserConsoleLogsCleared')}(${chalk.red(
108 'expected',
109 )})\n`;
110
111 if (logs.length > 0) {
112 message += `\nconsole.log was called without assertConsoleLogDev:\n${diff(
113 '',
114 logs.join('\n'),
115 {
116 omitAnnotationLines: true,
117 },
118 )}\n`;
119 }
120
121 if (warnings.length > 0) {
122 message += `\nconsole.warn was called without assertConsoleWarnDev:\n${diff(
123 '',
124 warnings.map(normalizeComponentStack).join('\n'),
125 {
126 omitAnnotationLines: true,
127 },
128 )}\n`;
129 }
130 if (errors.length > 0) {
131 message += `\nconsole.error was called without assertConsoleErrorDev:\n${diff(
132 '',
133 errors.map(normalizeComponentStack).join('\n'),
134 {
135 omitAnnotationLines: true,
136 },
137 )}\n`;
138 }
139
140 message += `\nYou must call one of the assertConsoleDev helpers between each act call.`;
141
142 const error = Error(message);
143 Error.captureStackTrace(error, assertConsoleLogsCleared);
144 throw error;
145 }
146}
147
148function normalizeCodeLocInfo(str) {
149 if (typeof str !== 'string') {

Callers 7

actFunction · 0.90
serverActFunction · 0.90
assertYieldsWereClearedFunction · 0.85
assertYieldsWereClearedFunction · 0.85
expectTestToFailFunction · 0.85
assertYieldsWereClearedFunction · 0.85

Calls 6

clearLogsFunction · 0.85
clearWarningsFunction · 0.85
clearErrorsFunction · 0.85
joinMethod · 0.80
mapMethod · 0.65
diffFunction · 0.50

Tested by

no test coverage detected