test: type the @actions/core spy/mock from the actual implementations

This allows the mockImplementation calls to automatically be typed based on the official @actions/core type definitions rather than having to define them manually.

Signed-off-by: Branden Cash <branden.cash@parchment.com>
This commit is contained in:
Branden Cash 2024-02-20 14:59:07 -07:00
parent 48e84f10c3
commit 506fd53fb1
No known key found for this signature in database
GPG Key ID: 2072CF23FE4BC869

View File

@ -16,11 +16,11 @@ const runMock = jest.spyOn(main, 'run')
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
let debugMock: jest.SpiedFunction<typeof core.debug>
let errorMock: jest.SpiedFunction<typeof core.error>
let getInputMock: jest.SpiedFunction<typeof core.getInput>
let setFailedMock: jest.SpiedFunction<typeof core.setFailed>
let setOutputMock: jest.SpiedFunction<typeof core.setOutput>
describe('action', () => {
beforeEach(() => {
@ -35,7 +35,7 @@ describe('action', () => {
it('sets the time output', async () => {
// Set the action's inputs as return values from core.getInput()
getInputMock.mockImplementation((name: string): string => {
getInputMock.mockImplementation(name => {
switch (name) {
case 'milliseconds':
return '500'
@ -67,7 +67,7 @@ describe('action', () => {
it('sets a failed status', async () => {
// Set the action's inputs as return values from core.getInput()
getInputMock.mockImplementation((name: string): string => {
getInputMock.mockImplementation(name => {
switch (name) {
case 'milliseconds':
return 'this is not a number'