Skip to content

Commit

Permalink
test: add tests for extractPackageApi
Browse files Browse the repository at this point in the history
  • Loading branch information
velut committed Feb 6, 2024
1 parent 0d8ea7f commit f01985d
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions src/extract-package-api.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { expect, test } from "vitest";
import {
InstallPackageError,
PackageNameError,
PackageTypesError,
} from "./errors";
import { extractPackageApi } from "./extract-package-api";

test("invalid package name", async () => {
const res = await extractPackageApi({ pkg: "" });
expect(res.isErr()).toBe(true);
expect(res._unsafeUnwrapErr() instanceof PackageNameError).toBe(true);
});

test("package not found", async () => {
const res = await extractPackageApi({ pkg: "@jsdocs-io/not-found" });
expect(res.isErr()).toBe(true);
expect(res._unsafeUnwrapErr() instanceof InstallPackageError).toBe(true);
});

test("package types not found", async () => {
const res = await extractPackageApi({ pkg: "[email protected]" });
expect(res.isErr()).toBe(true);
expect(res._unsafeUnwrapErr() instanceof PackageTypesError).toBe(true);
});

test("package successfully analyzed", async () => {
const res = await extractPackageApi({ pkg: "[email protected]" });
expect(res.isOk()).toBe(true);
});

0 comments on commit f01985d

Please sign in to comment.