From 51bc172a7a83688ace1bddfe22ef04ceb13572b9 Mon Sep 17 00:00:00 2001 From: Nick Alteen Date: Wed, 1 Nov 2023 13:43:25 -0400 Subject: [PATCH] Reset mocks on each test --- __tests__/main.test.ts | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/__tests__/main.test.ts b/__tests__/main.test.ts index 8205e39..30efdfb 100644 --- a/__tests__/main.test.ts +++ b/__tests__/main.test.ts @@ -9,26 +9,28 @@ import * as core from '@actions/core' import * as main from '../src/main' -// Mock the GitHub Actions core library -const debugMock = jest.spyOn(core, 'debug') -const getInputMock = jest.spyOn(core, 'getInput') -const setFailedMock = jest.spyOn(core, 'setFailed') -const setOutputMock = jest.spyOn(core, 'setOutput') - // Mock the action's main function const runMock = jest.spyOn(main, 'run') // Other utilities const timeRegex = /^\d{2}:\d{2}:\d{2}/ +// Mock the GitHub Actions core library +let debugMock: jest.SpyInstance +let errorMock: jest.SpyInstance +let getInputMock: jest.SpyInstance +let setFailedMock: jest.SpyInstance +let setOutputMock: jest.SpyInstance + describe('action', () => { beforeEach(() => { jest.clearAllMocks() - jest.spyOn(core, 'debug').mockImplementation() - jest.spyOn(core, 'error').mockImplementation() - jest.spyOn(core, 'getInput').mockImplementation() - jest.spyOn(core, 'setFailed').mockImplementation() - jest.spyOn(core, 'setOutput').mockImplementation() + + debugMock = jest.spyOn(core, 'debug').mockImplementation() + errorMock = jest.spyOn(core, 'error').mockImplementation() + getInputMock = jest.spyOn(core, 'getInput').mockImplementation() + setFailedMock = jest.spyOn(core, 'setFailed').mockImplementation() + setOutputMock = jest.spyOn(core, 'setOutput').mockImplementation() }) it('sets the time output', async () => { @@ -60,6 +62,7 @@ describe('action', () => { 'time', expect.stringMatching(timeRegex) ) + expect(errorMock).not.toHaveBeenCalled() }) it('sets a failed status', async () => { @@ -81,5 +84,6 @@ describe('action', () => { 1, 'milliseconds not a number' ) + expect(errorMock).not.toHaveBeenCalled() }) })