MCPcopy Index your code
hub / github.com/ampproject/amphtml / printWarning

Function printWarning

testing/console-logging-setup.js:69–95  ·  view source on GitHub ↗

* Prints a warning when a console error is detected during a test. * @param {*} messages One or more error messages

(...messages)

Source from the content-addressed store, hash-verified

67 * @param {*} messages One or more error messages
68 */
69function printWarning(...messages) {
70 const message = messages.join(' ');
71
72 const index = indexOfExpectedMessage(message);
73 if (index != -1) {
74 expectedAsyncErrors.splice(index, 1);
75 return;
76 }
77
78 const errorMessage = message.split('\n', 1)[0]; // First line.
79 const helpMessage =
80 ' The test "' +
81 testName +
82 '"' +
83 ' resulted in a call to console.error. (See above line.)\n' +
84 ' ⤷ If the error is not expected, fix the code that generated ' +
85 'the error.\n' +
86 ' ⤷ If the error is expected (and synchronous), use the following ' +
87 'pattern to wrap the test code that generated the error:\n' +
88 " 'allowConsoleError(() => { <code that generated the " +
89 "error> });'\n" +
90 ' ⤷ If the error is expected (and asynchronous), use the ' +
91 'following pattern at the top of the test:\n' +
92 " 'expectAsyncConsoleError(<string or regex>[, <number of" +
93 ' times the error message repeats>]);';
94 originalConsoleError(errorMessage + "'\n" + helpMessage);
95}
96
97/**
98 * Used during normal test execution, to detect unexpected console errors.

Callers

nothing calls this directly

Calls 1

indexOfExpectedMessageFunction · 0.85

Tested by

no test coverage detected