From b77f506d2076843bbc2cc23e9d18d39837d97ac0 Mon Sep 17 00:00:00 2001 From: Nick Alteen Date: Fri, 15 Sep 2023 12:38:47 -0400 Subject: [PATCH] Add mock implementations --- __tests__/main.test.ts | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/__tests__/main.test.ts b/__tests__/main.test.ts index 6cd4aee..1d8b25d 100644 --- a/__tests__/main.test.ts +++ b/__tests__/main.test.ts @@ -11,10 +11,10 @@ import * as main from '../src/main' // Mock the GitHub Actions core library //const debugMock = jest.spyOn(core, 'debug') -const infoMock = jest.spyOn(core, 'info') -const getInputMock = jest.spyOn(core, 'getInput') -const setFailedMock = jest.spyOn(core, 'setFailed') -const setOutputMock = jest.spyOn(core, 'setOutput') +const infoMock = jest.spyOn(core, 'info').mockImplementation() +const getInputMock = jest.spyOn(core, 'getInput').mockImplementation() +const setFailedMock = jest.spyOn(core, 'setFailed').mockImplementation() +const setOutputMock = jest.spyOn(core, 'setOutput').mockImplementation() // Mock the action's main function const runMock = jest.spyOn(main, 'run') @@ -57,16 +57,12 @@ describe('action', () => { } }) - try { - await main.run() + await main.run() - expect(runMock).toHaveReturned() - expect(setFailedMock).toHaveBeenNthCalledWith( - 1, - 'milliseconds not a number' - ) - } catch (error) { - console.log(error) - } + expect(runMock).toHaveReturned() + expect(setFailedMock).toHaveBeenNthCalledWith( + 1, + 'milliseconds not a number' + ) }) })