Skip to content

Commit

Permalink
test: add test for yarn.version function
Browse files Browse the repository at this point in the history
  • Loading branch information
threeal committed Feb 17, 2024
1 parent 4e5b4e2 commit 017ace0
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/yarn.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { jest } from "@jest/globals";

jest.unstable_mockModule("@actions/exec", () => ({
exec: jest.fn(),
getExecOutput: jest.fn(),
}));

beforeEach(() => {
Expand Down Expand Up @@ -50,3 +51,17 @@ it("should install package using Yarn", async () => {
},
});
});

it("should get Yarn version", async () => {
const { getExecOutput } = await import("@actions/exec");
const yarn = (await import("./yarn.mjs")).default;

getExecOutput.mockResolvedValue({ stdout: "1.2.3" });

const version = await yarn.version();

expect(getExecOutput).toHaveBeenCalledTimes(1);
expect(getExecOutput).toHaveBeenCalledWith("corepack", ["yarn", "--version"]);

expect(version).toEqual("1.2.3");
});

0 comments on commit 017ace0

Please sign in to comment.