()
| 98 | * Used during normal test execution, to detect unexpected console errors. |
| 99 | */ |
| 100 | export function warnForConsoleError() { |
| 101 | expectedAsyncErrors = []; |
| 102 | consoleErrorSandbox = sinon.createSandbox(); |
| 103 | const consoleErrorStub = consoleErrorSandbox |
| 104 | .stub(console, 'error') |
| 105 | .callsFake(printWarning); |
| 106 | |
| 107 | self.expectAsyncConsoleError = function (message, repeat = 1) { |
| 108 | expectedAsyncErrors.push.apply( |
| 109 | expectedAsyncErrors, |
| 110 | Array(repeat).fill(message) |
| 111 | ); |
| 112 | }; |
| 113 | self.allowConsoleError = function (func) { |
| 114 | consoleErrorStub.reset(); |
| 115 | consoleErrorStub.callsFake(() => {}); |
| 116 | const result = func(); |
| 117 | try { |
| 118 | expect(consoleErrorStub).to.have.been.called; |
| 119 | } catch (e) { |
| 120 | const helpMessage = |
| 121 | 'The test "' + |
| 122 | testName + |
| 123 | '" contains an "allowConsoleError" block ' + |
| 124 | "that didn't result in a call to console.error."; |
| 125 | originalConsoleError(helpMessage); |
| 126 | } finally { |
| 127 | consoleErrorStub.callsFake(printWarning); |
| 128 | } |
| 129 | return result; |
| 130 | }; |
| 131 | } |
| 132 | |
| 133 | /** |
| 134 | * Used to restore error level logging after each test. |
no test coverage detected