evcc-io/assets/js/utils/cleanYaml.test.ts
Maschga d07a0741ec
chore: use vite+ (#32297)
Co-authored-by: Michael Geers <michael@geers.tv>
2026-07-31 11:43:57 +02:00

31 lines
1.2 KiB
TypeScript

import { describe, expect, test } from "vite-plus/test";
import { cleanYaml } from "./cleanYaml";
describe("cleanYaml", () => {
test("removes key from single line", () => {
const result = cleanYaml("key: value", "key");
expect(result).toBe("value");
});
test("removes key from multi-line yaml", () => {
const input = `key:\n nested: value\n another: thing`;
const expected = `nested: value\nanother: thing`;
const result = cleanYaml(input, "key");
expect(result).toBe(expected);
});
test("keep untouched if key not found", () => {
const result = cleanYaml("key: value", "not-found");
expect(result).toBe("key: value");
});
test("trim whitespace at the end of the line", () => {
const result = cleanYaml("key: \n - foo \n - bar ", "key");
expect(result).toBe("- foo\n- bar");
});
test("should remove leading comment lines", () => {
const result = cleanYaml("# this is\n# a comment\nkey: value", "key");
expect(result).toBe("value");
});
test("should note remove leading comment lines if key is not found", () => {
const result = cleanYaml("# this is\n# a comment\nnot-found: value", "key");
expect(result).toBe("# this is\n# a comment\nnot-found: value");
});
});