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:
parent
48e84f10c3
commit
506fd53fb1
|
@ -16,11 +16,11 @@ const runMock = jest.spyOn(main, 'run')
|
||||||
const timeRegex = /^\d{2}:\d{2}:\d{2}/
|
const timeRegex = /^\d{2}:\d{2}:\d{2}/
|
||||||
|
|
||||||
// Mock the GitHub Actions core library
|
// Mock the GitHub Actions core library
|
||||||
let debugMock: jest.SpyInstance
|
let debugMock: jest.SpiedFunction<typeof core.debug>
|
||||||
let errorMock: jest.SpyInstance
|
let errorMock: jest.SpiedFunction<typeof core.error>
|
||||||
let getInputMock: jest.SpyInstance
|
let getInputMock: jest.SpiedFunction<typeof core.getInput>
|
||||||
let setFailedMock: jest.SpyInstance
|
let setFailedMock: jest.SpiedFunction<typeof core.setFailed>
|
||||||
let setOutputMock: jest.SpyInstance
|
let setOutputMock: jest.SpiedFunction<typeof core.setOutput>
|
||||||
|
|
||||||
describe('action', () => {
|
describe('action', () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
|
@ -35,7 +35,7 @@ describe('action', () => {
|
||||||
|
|
||||||
it('sets the time output', async () => {
|
it('sets the time output', async () => {
|
||||||
// Set the action's inputs as return values from core.getInput()
|
// Set the action's inputs as return values from core.getInput()
|
||||||
getInputMock.mockImplementation((name: string): string => {
|
getInputMock.mockImplementation(name => {
|
||||||
switch (name) {
|
switch (name) {
|
||||||
case 'milliseconds':
|
case 'milliseconds':
|
||||||
return '500'
|
return '500'
|
||||||
|
@ -67,7 +67,7 @@ describe('action', () => {
|
||||||
|
|
||||||
it('sets a failed status', async () => {
|
it('sets a failed status', async () => {
|
||||||
// Set the action's inputs as return values from core.getInput()
|
// Set the action's inputs as return values from core.getInput()
|
||||||
getInputMock.mockImplementation((name: string): string => {
|
getInputMock.mockImplementation(name => {
|
||||||
switch (name) {
|
switch (name) {
|
||||||
case 'milliseconds':
|
case 'milliseconds':
|
||||||
return 'this is not a number'
|
return 'this is not a number'
|
||||||
|
|
Loading…
Reference in New Issue