test: add vitest for unit tests (#50)

* feat: add vitest for unit tests

* chore: address pull request feedback

* test: add unit test code quality workflow
This commit is contained in:
Meier Lukas
2024-02-04 09:47:23 +01:00
committed by GitHub
parent ca04bf692d
commit ae12f0c9df
6 changed files with 1119 additions and 87 deletions

View File

@@ -0,0 +1,10 @@
import { describe, expect, it } from "vitest";
import { objectKeys } from "../object";
describe("objectKeys should return all keys of an object", () => {
it("should return all keys of an object", () => {
const obj = { a: 1, b: 2, c: 3 };
expect(objectKeys(obj)).toEqual(["a", "b", "c"]);
});
});

View File

@@ -0,0 +1,19 @@
import { describe, expect, it } from "vitest";
import { capitalize } from "../string";
const capitalizeTestCases = [
["hello", "Hello"],
["World", "World"],
["123", "123"],
["a", "A"],
["two words", "Two words"],
] as const;
describe("capitalize should capitalize the first letter of a string", () => {
capitalizeTestCases.forEach(([input, expected]) => {
it(`should capitalize ${input} to ${expected}`, () => {
expect(capitalize(input)).toEqual(expected);
});
});
});