-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjest.afterEnv.js
More file actions
36 lines (30 loc) · 1.2 KB
/
jest.afterEnv.js
File metadata and controls
36 lines (30 loc) · 1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
// This file runs AFTER the Jest test framework is installed
// Use this for setup that requires Jest APIs (jest.fn, expect, beforeEach, etc.)
// Suppress console output during tests to keep output clean
// This reduces noise from expected error messages in error-handling tests
// Store original console methods
const originalConsoleError = console.error;
const originalConsoleLog = console.log;
const originalConsoleWarn = console.warn;
const originalConsoleDebug = console.debug;
// Override console methods using Jest APIs
console.error = jest.fn((...args) => {
// Only log actual test failures, not expected errors from the code
const message = args[0]?.toString() || '';
// Allow through only critical Jest errors
if (message.includes('FAIL') || message.includes('●')) {
originalConsoleError(...args);
}
// Suppress all other console.error (like expected API errors in tests)
});
console.log = jest.fn((...args) => {
// Suppress all console.log during tests
// Uncomment to debug:
// originalConsoleLog(...args);
});
console.warn = jest.fn((...args) => {
// Suppress all console.warn during tests
});
console.debug = jest.fn((...args) => {
// Suppress all console.debug during tests
});