Skip to content

Commit f769078

Browse files
committed
test: add unit tests for some action input validation
Signed-off-by: Sebastian Beltran <[email protected]>
1 parent e48875c commit f769078

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

__tests__/action.test.js

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
const core = require('@actions/core')
2+
const main = require('../src/action')
3+
4+
// Mock the GitHub Actions core library
5+
const debugMock = jest.spyOn(core, 'debug').mockImplementation()
6+
const getInputMock = jest.spyOn(core, 'getInput').mockImplementation()
7+
const setFailedMock = jest.spyOn(core, 'setFailed').mockImplementation()
8+
const setOutputMock = jest.spyOn(core, 'setOutput').mockImplementation()
9+
10+
// Mock the action's main function
11+
const runMock = jest.spyOn(main, 'run')
12+
13+
describe('action', () => {
14+
beforeEach(() => {
15+
jest.clearAllMocks()
16+
})
17+
18+
it.each(["scope", "database", "report"])('should throw an error if the %s is not provided', async (input) => {
19+
getInputMock.mockImplementation(name => {
20+
if (name === input) {
21+
throw new Error(`Input required and not supplied: ${input}`)
22+
}
23+
24+
return ''
25+
})
26+
await main.run()
27+
28+
expect(runMock).toHaveReturned()
29+
expect(setFailedMock).toHaveBeenNthCalledWith(
30+
1,
31+
`Input required and not supplied: ${input}`
32+
)
33+
})
34+
})

0 commit comments

Comments
 (0)