Add mocks to tests
This commit is contained in:
36
__tests__/Action.test.ts
Normal file
36
__tests__/Action.test.ts
Normal file
@@ -0,0 +1,36 @@
|
||||
import { Action } from "../src/Action";
|
||||
import { Inputs } from "../src/Inputs";
|
||||
import { Releases } from "../src/Releases";
|
||||
|
||||
|
||||
describe("Action", () => {
|
||||
|
||||
it('verifies my sanity', () => {
|
||||
|
||||
})
|
||||
})
|
||||
|
||||
function createAction(): Action {
|
||||
const MockReleases = jest.fn<Releases, any>(() => {
|
||||
return {
|
||||
create: jest.fn(),
|
||||
uploadArtifact: jest.fn()
|
||||
}
|
||||
})
|
||||
const MockInputs = jest.fn<Inputs, any>(() => {
|
||||
return {
|
||||
artifact: "foo",
|
||||
artifactContentType: "foo",
|
||||
artifactContentLength: 22,
|
||||
body: "bar",
|
||||
commit: "foo",
|
||||
name: "name",
|
||||
tag: "foo",
|
||||
token: "foo"
|
||||
}
|
||||
})
|
||||
const inputs = new MockInputs()
|
||||
const releases = new MockReleases()
|
||||
|
||||
return new Action(inputs, releases)
|
||||
}
|
||||
@@ -2,20 +2,20 @@ const mockGetInput = jest.fn();
|
||||
const mockReadFileSync = jest.fn();
|
||||
const mockStatSync = jest.fn();
|
||||
|
||||
import { Inputs } from "../src/Inputs";
|
||||
import { Inputs, CoreInputs } from "../src/Inputs";
|
||||
import { Context } from "@actions/github/lib/context";
|
||||
|
||||
|
||||
jest.mock('@actions/core', () => {
|
||||
return { getInput: mockGetInput };
|
||||
});
|
||||
})
|
||||
|
||||
jest.mock('fs', () => {
|
||||
return {
|
||||
readFileSync: mockReadFileSync,
|
||||
statSync: mockStatSync
|
||||
};
|
||||
});
|
||||
})
|
||||
|
||||
describe('Inputs', () => {
|
||||
let context: Context;
|
||||
@@ -23,7 +23,7 @@ describe('Inputs', () => {
|
||||
beforeEach(() => {
|
||||
mockGetInput.mockReturnValue(null)
|
||||
context = new Context()
|
||||
inputs = new Inputs(context)
|
||||
inputs = new CoreInputs(context)
|
||||
})
|
||||
|
||||
it('returns artifact', () => {
|
||||
@@ -58,21 +58,32 @@ describe('Inputs', () => {
|
||||
})
|
||||
})
|
||||
|
||||
describe('description', () => {
|
||||
it('returns input description', () => {
|
||||
mockGetInput.mockReturnValue("description")
|
||||
expect(inputs.description).toBe("description")
|
||||
describe('body', () => {
|
||||
it('returns input body', () => {
|
||||
mockGetInput.mockReturnValue("body")
|
||||
expect(inputs.body).toBe("body")
|
||||
})
|
||||
|
||||
it('returns description file contents', () => {
|
||||
it('returns body file contents', () => {
|
||||
mockGetInput.mockReturnValueOnce("").mockReturnValueOnce("a/path")
|
||||
mockReadFileSync.mockReturnValue("file")
|
||||
|
||||
expect(inputs.description).toBe("file")
|
||||
expect(inputs.body).toBe("file")
|
||||
})
|
||||
|
||||
it('returns empty', () => {
|
||||
expect(inputs.description).toBe("")
|
||||
expect(inputs.body).toBe("")
|
||||
})
|
||||
})
|
||||
|
||||
describe('draft', () => {
|
||||
it('returns false', () => {
|
||||
expect(inputs.draft).toBe(false)
|
||||
})
|
||||
|
||||
it('returns true', () => {
|
||||
mockGetInput.mockReturnValue("true")
|
||||
expect(inputs.draft).toBe(true)
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user