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

Function warnForConsoleError

testing/console-logging-setup.js:100–131  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

98 * Used during normal test execution, to detect unexpected console errors.
99 */
100export 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.

Callers 1

setupTestcaseFunction · 0.90

Calls 4

funcFunction · 0.85
expectFunction · 0.85
applyMethod · 0.80
resetMethod · 0.45

Tested by

no test coverage detected