forked from gerred/current-time
-
Notifications
You must be signed in to change notification settings - Fork 0
/
action.test.js
42 lines (35 loc) · 1.04 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
const mockMoment = {
format: jest.fn()
};
jest.doMock('moment', () => () => mockMoment);
const mockCore = {
getInput: jest.fn(),
setOutput: jest.fn(),
setFailed: jest.fn(),
};
jest.doMock('@actions/core', () => mockCore);
const mockDate = {
toISOString: jest.fn(),
};
Date = function () { return mockDate; }
const action = require('./action.js');
describe("action", () => {
it("Should load", () => {
expect(action).not.toBeNull();
});
it("Should run with original functionality", () => {
mockDate.toISOString.mockReturnValue('##');
action();
expect(mockCore.setOutput).toHaveBeenCalledWith('time', '##');
});
it("Should run with format", () => {
mockMoment.format.mockReturnValue('###');
action();
expect(mockCore.setOutput).toHaveBeenCalledWith('formattedTime', '###');
});
it("Should pass format input", () => {
mockCore.getInput.mockReturnValue('###');
action();
expect(mockMoment.format).toHaveBeenCalledWith('###');
});
});