From 9195ba26449caad29ba4bb867333aba7051049d6 Mon Sep 17 00:00:00 2001 From: Aleem Isiaka Date: Tue, 15 Aug 2023 10:47:38 +0100 Subject: [PATCH] Tests for errors and warnings --- test/log.test.ts | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/test/log.test.ts b/test/log.test.ts index ba19534..42f0b19 100644 --- a/test/log.test.ts +++ b/test/log.test.ts @@ -3,7 +3,10 @@ const Log = require('../dist'); const mockedLog = jest.fn(); const mockConsoleLog = () => { + mockedLog.mockReset(); console.log = mockedLog; + console.warn = mockedLog; + console.error = mockedLog; }; let secureLog; @@ -13,7 +16,7 @@ const setup = (options = {}) => { }; describe('Test console.log', () => { - beforeAll(() => { + beforeEach(() => { setup(); }); it('should have called console.log with hello', () => { @@ -24,4 +27,14 @@ describe('Test console.log', () => { 'hello' ); }); + + it('should have called console.warn with hello warn', () => { + secureLog.warn('hello warn'); + expect(mockedLog).toHaveBeenCalledWith('hello warn'); + }); + + it('should have called console.error with hello error', () => { + secureLog.error('hello error'); + expect(mockedLog).toHaveBeenCalledWith('hello error'); + }); });