Add tests
This commit is contained in:
parent
8a13446fe4
commit
56ed9a477f
|
@ -127,31 +127,59 @@ describe("Test that the object processing works correctly", () => {
|
||||||
})
|
})
|
||||||
|
|
||||||
describe("check arrays", () => {
|
describe("check arrays", () => {
|
||||||
it.each([
|
describe("index with square brackets", () => {
|
||||||
[0, "1"],
|
it.each([
|
||||||
[1, "2"],
|
[0, "1"],
|
||||||
])("should handle an array of primitive types", async (index, expected) => {
|
[1, "2"],
|
||||||
const json = [1, 2, 3]
|
])("should handle an array of primitive types", async (index, expected) => {
|
||||||
const output = await processString(`{{ testing.${index} }}`, {
|
const json = [1, 2, 3]
|
||||||
testing: json,
|
const output = await processString(`{{ testing.[${index}] }}`, {
|
||||||
|
testing: json,
|
||||||
|
})
|
||||||
|
expect(output).toEqual(expected)
|
||||||
|
})
|
||||||
|
|
||||||
|
it("should handle an array of objects", async () => {
|
||||||
|
const json = [{ value: 1 }, { value: 2 }, { value: 3 }]
|
||||||
|
const output = await processString("{{ testing.[1] }}", {
|
||||||
|
testing: json,
|
||||||
|
})
|
||||||
|
expect(output).toEqual('{"value":2}')
|
||||||
|
})
|
||||||
|
|
||||||
|
it("should handle nesting properties in an array of objects", async () => {
|
||||||
|
const json = [{ value: 1 }, { value: 2 }, { value: 3 }]
|
||||||
|
const output = await processString("{{ testing.[1].value }}", {
|
||||||
|
testing: json,
|
||||||
|
})
|
||||||
|
expect(output).toEqual("2")
|
||||||
})
|
})
|
||||||
expect(output).toEqual(expected)
|
|
||||||
})
|
})
|
||||||
|
|
||||||
it("should handle an array of object types", async () => {
|
describe("index without square brackets", () => {
|
||||||
const json = [{ value: 1 }, { value: 2 }, { value: 3 }]
|
it("should not handle an array of primitive types", async () => {
|
||||||
const output = await processString("{{ testing.0 }}", {
|
const json = [1, 2, 3]
|
||||||
testing: json,
|
const output = await processString(`{{ testing.1 }}`, {
|
||||||
|
testing: json,
|
||||||
|
})
|
||||||
|
expect(output).toEqual("{{ testing.1 }}")
|
||||||
})
|
})
|
||||||
expect(output).toEqual({ value: 1 })
|
|
||||||
})
|
|
||||||
|
|
||||||
it("should handle nesting properties in an array of object types", async () => {
|
it("should not handle an array of objects", async () => {
|
||||||
const json = [{ value: 1 }, { value: 2 }, { value: 3 }]
|
const json = [{ value: 1 }, { value: 2 }, { value: 3 }]
|
||||||
const output = await processString("{{ testing.0.value }}", {
|
const output = await processString("{{ testing.1 }}", {
|
||||||
testing: json,
|
testing: json,
|
||||||
|
})
|
||||||
|
expect(output).toEqual("{{ testing.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.1.value }}", {
|
||||||
|
testing: json,
|
||||||
|
})
|
||||||
|
expect(output).toEqual("2")
|
||||||
})
|
})
|
||||||
expect(output).toEqual("1")
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue