* Prints a warning when a console error is detected during a test. * @param {*} messages One or more error messages
(...messages)
| 67 | * @param {*} messages One or more error messages |
| 68 | */ |
| 69 | function 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. |
nothing calls this directly
no test coverage detected