From b5d29ce9dcabd1c201265be62a8ae0bb85d2c474 Mon Sep 17 00:00:00 2001 From: Danielo Rodriguez Date: Thu, 26 Oct 2023 13:29:16 +0200 Subject: [PATCH] tests: frontmatterString pick/omit --- src/core/FormResult.test.ts | 49 +++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/src/core/FormResult.test.ts b/src/core/FormResult.test.ts index 096e3ec5..c38c1914 100644 --- a/src/core/FormResult.test.ts +++ b/src/core/FormResult.test.ts @@ -104,4 +104,53 @@ age:: 30`; ).toEqual(expectedOutput); }); }); + describe("asFrontmatterString pick/omit", () => { + it("should return the data as a YAML frontmatter string with only the specified keys using options.pick", () => { + const result = new FormResult(formData, "ok"); + const expectedOutput = `name: John Doe +age: 30`; + expect( + result.asFrontmatterString({ pick: ["name", "age"] }).trim() + ).toEqual(expectedOutput); + }); + + it("should return the data as a YAML frontmatter string with all keys except the specified ones using options.omit", () => { + const result = new FormResult(formData, "ok"); + const expectedOutput = `name: John Doe +age: 30`; + expect( + result + .asFrontmatterString({ omit: ["hobbies", "isEmployed"] }) + .trim() + ).toEqual(expectedOutput); + }); + + it("should return the data as a YAML frontmatter string with only the specified keys using options.pick and ignoring options.omit", () => { + const result = new FormResult(formData, "ok"); + const expectedOutput = `name: John Doe +age: 30`; + expect( + result + .asFrontmatterString({ + pick: ["name", "age"], + omit: ["hobbies", "isEmployed"], + }) + .trim() + ).toEqual(expectedOutput); + }); + + it("should return the data as a YAML frontmatter string with all keys except the specified ones using options.omit and ignoring options.pick", () => { + const result = new FormResult(formData, "ok"); + const expectedOutput = `name: John Doe +age: 30`; + expect( + result + .asFrontmatterString({ + omit: ["hobbies", "isEmployed"], + pick: ["name", "age"], + }) + .trim() + ).toEqual(expectedOutput); + }); + }); });