Add tests

This commit is contained in:
Adria Navarro 2024-03-25 13:22:57 +01:00
parent 7e7f31b967
commit 35a0a4d44c
1 changed files with 29 additions and 0 deletions

View File

@ -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", () => { describe("check returning objects", () => {
it("should handle an array of objects", async () => { it("should handle an array of objects", async () => {
const json = [{ a: 1 }, { a: 2 }] const json = [{ a: 1 }, { a: 2 }]