@applicaster/zapplicaster-cli
Version:
CLI Tool for the zapp app and Quick Brick project
55 lines (44 loc) • 1.75 kB
JavaScript
const R = require("ramda");
const { registerCommand, commands } = require("../index");
jest.mock("commander");
jest.mock("fs", () => require("../../../test_helpers/fsMock"));
const program = require("commander");
const programCommand = jest.spyOn(program, "command");
const programOption = jest.spyOn(program, "option");
const programAction = jest.spyOn(program, "action");
describe("commands", () => {
it("is an array with 7 entry", () => {
expect(Array.isArray(commands)).toBe(true);
expect(commands).toHaveLength(7);
});
it("each item has the appropriate structure", () => {
commands.forEach((command) => {
expect(command).toHaveProperty("syntax");
expect(typeof command.syntax).toBe("string");
expect(command).toHaveProperty("options");
expect(Array.isArray(command.options)).toBe(true);
expect(command).toHaveProperty("action");
expect(typeof command.action).toBe("function");
});
});
});
describe("registerCommand", () => {
let commandRegistrationFunction;
beforeEach(() => {
commandRegistrationFunction = registerCommand(program);
});
it("returns a function", () => {
expect(typeof commandRegistrationFunction).toBe("function");
});
it("invokes the proper commander methods", () => {
commandRegistrationFunction(commands[0]);
expect(programCommand).toHaveBeenCalledTimes(1);
expect(programCommand).toHaveBeenCalledWith(commands[0].syntax);
expect(programOption).toHaveBeenCalledTimes(commands[0].options.length);
expect(programOption).toHaveBeenLastCalledWith(
...R.last(commands[0].options)
);
expect(programAction).toHaveBeenCalledTimes(1);
expect(programAction).toHaveBeenCalledWith(commands[0].action);
});
});