This repository has been archived by the owner on Jun 19, 2024. It is now read-only.
forked from josStorer/get-current-time
-
Notifications
You must be signed in to change notification settings - Fork 0
/
action.test.js
63 lines (55 loc) · 2.18 KB
/
action.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
53
54
55
56
57
58
59
60
61
62
63
const mockMoment = {
utcOffset: jest.fn().mockReturnThis(),
format: jest.fn(),
toISOString: jest.fn(),
toString: jest.fn(),
toArray: jest.fn()
};
jest.doMock('moment', () => () => mockMoment);
const mockCore = {
getInput: jest.fn(),
setOutput: jest.fn(),
setFailed: jest.fn(),
};
jest.doMock('@actions/core', () => mockCore);
const action = require('./action.js');
describe("action", () => {
it("Should load", () => {
expect(action).not.toBeNull();
});
it("Should run with basic functionality", () => {
mockMoment.toISOString.mockReturnValue('##');
mockMoment.toString.mockReturnValue('##');
action();
expect(mockCore.setOutput).toHaveBeenCalledWith('time', '##');
expect(mockCore.setOutput).toHaveBeenCalledWith('ISOTime', '##');
expect(mockCore.setOutput).toHaveBeenCalledWith('readableTime', '##');
});
it("Should run with format", () => {
mockMoment.format.mockReturnValue('###');
action();
expect(mockCore.setOutput).toHaveBeenCalledWith('formattedTime', '###');
});
it("Should run with other basic outputs", () => {
mockMoment.toArray.mockReturnValue(['2020', '0', '1', '12', '0', '1', '2']);
action();
expect(mockCore.setOutput).toHaveBeenCalledWith('year', '2020');
expect(mockCore.setOutput).toHaveBeenCalledWith('month', '1');
expect(mockCore.setOutput).toHaveBeenCalledWith('day', '1');
expect(mockCore.setOutput).toHaveBeenCalledWith('hour', '12');
expect(mockCore.setOutput).toHaveBeenCalledWith('minute', '0');
expect(mockCore.setOutput).toHaveBeenCalledWith('second', '1');
expect(mockCore.setOutput).toHaveBeenCalledWith('millisecond', '2');
});
it("Should pass format inputs", () => {
mockCore.getInput.mockReturnValue('###');
action();
expect(mockMoment.utcOffset).toHaveBeenCalledWith('###');
expect(mockMoment.format).toHaveBeenCalledWith('###');
});
it("Should throw error", () => {
mockCore.setOutput = () => { throw new Error('####') }
action();
expect(mockCore.setFailed).toHaveBeenCalledWith('####');
});
});