Skip to content

Commit 06ac77b

Browse files
authored
[test] Fix unexpected console warn/error spy swallowing unrelated messages (#23312)
1 parent ec391c7 commit 06ac77b

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

test/utils/mochaHooks.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,19 @@ function createUnexpectedConsoleMessagesHooks(Mocha, methodName, expectedMatcher
2626
]);
2727
}
2828

29+
let originalConsoleMethod;
2930
mochaHooks.beforeAll.push(function registerConsoleStub() {
31+
// eslint-disable-next-line no-console
32+
originalConsoleMethod = console[methodName];
3033
// eslint-disable-next-line no-console
3134
console[methodName] = logUnexpectedConsoleCalls;
3235
});
3336

37+
mochaHooks.afterAll.push(function registerConsoleStub() {
38+
// eslint-disable-next-line no-console
39+
console[methodName] = originalConsoleMethod;
40+
});
41+
3442
mochaHooks.afterEach.push(function flushUnexpectedCalls() {
3543
const hadUnexpectedCalls = unexpectedCalls.length > 0;
3644
const formattedCalls = unexpectedCalls.map(

0 commit comments

Comments
 (0)