-
Notifications
You must be signed in to change notification settings - Fork 230
/
Copy pathmain.test.js
52 lines (40 loc) · 1.27 KB
/
main.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/**
* Unit tests for the action's main functionality, src/main.js
*/
import { afterEach, beforeEach, jest } from '@jest/globals'
const core = await import('../__fixtures__/core')
const github = await import('../__fixtures__/github')
jest.unstable_mockModule('@actions/core', () => core)
jest.unstable_mockModule('@actions/github', () => github)
const main = await import('../src/main')
describe('action', () => {
beforeEach(() => {
// Mock the action's inputs
core.getInput.mockReturnValueOnce('World')
// Mock the action's payload
github.context.payload = {
actor: 'mona'
}
})
afterEach(() => {
jest.resetAllMocks()
})
it('sets the time output', async () => {
await main.run()
expect(core.setOutput).toHaveBeenCalledWith('time', expect.any(String))
})
it('logs the event payload', async () => {
await main.run()
expect(core.info).toHaveBeenCalledWith(
`The event payload: ${JSON.stringify(github.context.payload, null, 2)}`
)
})
it('sets a failed status', async () => {
// Mock a failure
core.getInput.mockReset().mockImplementation((name) => {
throw new Error('Something went wrong...')
})
await main.run()
expect(core.setFailed).toHaveBeenCalledWith('Something went wrong...')
})
})