From 35a0a4d44ca885fb9c2f55d53245f10b200aab91 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Mon, 25 Mar 2024 13:22:57 +0100 Subject: [PATCH] Add tests --- packages/string-templates/test/basic.spec.ts | 29 ++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/packages/string-templates/test/basic.spec.ts b/packages/string-templates/test/basic.spec.ts index 00058d4ecd..a9cf909aad 100644 --- a/packages/string-templates/test/basic.spec.ts +++ b/packages/string-templates/test/basic.spec.ts @@ -126,6 +126,35 @@ describe("Test that the object processing works correctly", () => { }) }) +describe("check arrays", () => { + it.each([ + [0, "1"], + [1, "2"], + ])("should handle an array of primitive types", async (index, expected) => { + const json = [1, 2, 3] + const output = await processString(`{{ testing.${index} }}`, { + testing: json, + }) + expect(output).toEqual(expected) + }) + + it("should handle an array of object types", async () => { + const json = [{ value: 1 }, { value: 2 }, { value: 3 }] + const output = await processString("{{ testing.0 }}", { + testing: json, + }) + expect(output).toEqual({ value: 1 }) + }) + + it("should handle nesting properties in an array of object types", async () => { + const json = [{ value: 1 }, { value: 2 }, { value: 3 }] + const output = await processString("{{ testing.0.value }}", { + testing: json, + }) + expect(output).toEqual("1") + }) +}) + describe("check returning objects", () => { it("should handle an array of objects", async () => { const json = [{ a: 1 }, { a: 2 }]