aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/packages/turbo-test-utils/src/spyConsole.ts
blob: 61722a5a224677f372daed779136d25b3e8a839d (plain) (blame)
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
export type SpyConsole = { log?: any; error?: any; warn?: any };

export default function spyConsole() {
  let spy: SpyConsole = {};

  beforeEach(() => {
    spy.log = jest.spyOn(console, "log").mockImplementation(() => {});
    spy.error = jest.spyOn(console, "error").mockImplementation(() => {});
    spy.warn = jest.spyOn(console, "warn").mockImplementation(() => {});
  });

  afterEach(() => {
    spy.log.mockClear();
    spy.error.mockClear();
    spy.warn.mockClear();
  });

  afterAll(() => {
    spy.log.mockRestore();
    spy.error.mockRestore();
    spy.warn.mockRestore();
  });

  return spy;
}