test(cli): add tests for generate command

This commit is contained in:
Ayo Ayco 2024-12-07 20:40:15 +01:00
parent 41d8ff83a5
commit ea06089c4a
2 changed files with 25 additions and 2 deletions

View file

@ -3,12 +3,20 @@
import { consola } from "consola";
import { defineCommand } from "citty";
function generate() {
consola.box("Generate a McFly building block (In-progress)");
}
export default defineCommand({
meta: {
name: "prepare",
description: "Generates building blocks for a McFly app.",
},
async run() {
consola.box("Generate a McFly building block (In-progress)");
run() {
generate();
},
});
export const exportedForTest = {
generate,
};

View file

@ -0,0 +1,15 @@
import { expect, test, vi } from "vitest";
import { exportedForTest } from "../commands/generate.mjs";
import consola from "consola";
const testFn = exportedForTest.generate;
test("show box message in-progress", () => {
const spy = vi.spyOn(consola, "box");
testFn();
const arg = spy.mock.calls[0][0];
expect(spy).toHaveBeenCalled();
expect(arg).toContain("In-progress");
});