File size: 374 Bytes
1e92f2d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
export const captureConsole =
( testFn ) =>
( callback = () => {} ) => {
const original = globalThis.console;
const replacement = {
log: jest.fn(),
warn: jest.fn(),
error: jest.fn(),
};
globalThis.console = replacement;
let val;
try {
val = testFn();
} finally {
globalThis.console = original;
}
callback( replacement );
return val;
};
|