@lukasbach/scripts

react/vitest-logic

Template for a vitest test suite file for a logic component.

Usage

npx @lukasbach/scripts react/vitest-logic

You can call the script directly if you have installed it globally:

npm i -g @lukasbach/scripts
ldo react/vitest-logic

There is a default shortcut for this script: ldo vitl

You can customize shortcuts with ldo edit-shortcuts.

Arguments

  • [0]: Name of the tested component

Options

  • -v, --verbose: Verbose logging

You can also omit options, and will be asked for them interactively.

Add --yes to skip all confirmations.

Script source

View Source on GitHub

/** Template for a vitest test suite file for a logic component. */

const testName = await ask.text("_", "Name of the tested component", "MyComponent");

const pascal = utils.changeCase.pascalCase(testName);
const kebab = utils.changeCase.kebabCase(testName);

const content = utils.noindent(`
  import { describe, expect, it } from "vitest";
  import { ${pascal} } from "./${kebab}";
  
  describe("${kebab}", () => {
    it("should work", () => {
      expect(() => ${pascal}())).toEqual(123);
    });
  });`);

await fs.writeFile(path.join(process.cwd(), `${kebab}.spec.ts`), content);