|
| 1 | +import { afterEach, beforeEach, describe, expect, it } from 'vitest'; |
| 2 | +import { mockConsole, unmockConsole } from './mock/helper.mock'; |
| 3 | +import { verboseUtils } from './verbose-utils'; |
| 4 | + |
| 5 | +const verboseHelper = verboseUtils(true); |
| 6 | +const noVerboseHelper = verboseUtils(false); |
| 7 | +describe('verbose-utils', () => { |
| 8 | + let logs: string[] = []; |
| 9 | + beforeEach(() => { |
| 10 | + mockConsole(args => logs.push(args)); |
| 11 | + }); |
| 12 | + afterEach(() => { |
| 13 | + logs = []; |
| 14 | + unmockConsole(); |
| 15 | + }); |
| 16 | + |
| 17 | + it('exec should work verbose', () => { |
| 18 | + const spy = vi.fn(); |
| 19 | + verboseHelper.exec(spy); |
| 20 | + expect(spy).toHaveBeenCalled(); |
| 21 | + expect(logs.length).toBe(0); |
| 22 | + }); |
| 23 | + |
| 24 | + it('exec should work no-verbose', () => { |
| 25 | + const spy = vi.fn(); |
| 26 | + noVerboseHelper.exec(spy); |
| 27 | + expect(spy).not.toHaveBeenCalled(); |
| 28 | + expect(logs.length).toBe(0); |
| 29 | + }); |
| 30 | + |
| 31 | + it('log should work verbose', () => { |
| 32 | + verboseHelper.log('42'); |
| 33 | + expect(logs.length).toBe(1); |
| 34 | + expect(logs[0]).toBe('42'); |
| 35 | + }); |
| 36 | + |
| 37 | + it('log should work no-verbose', () => { |
| 38 | + noVerboseHelper.log('42'); |
| 39 | + expect(logs.length).toBe(0); |
| 40 | + }); |
| 41 | +}); |
0 commit comments