2021-01-19 19:44:29 +01:00
|
|
|
const {
|
|
|
|
processString,
|
|
|
|
} = require("../src/index")
|
|
|
|
|
|
|
|
describe("Handling context properties with spaces in their name", () => {
|
2021-01-20 19:12:16 +01:00
|
|
|
it("should allow through literal specifiers", async () => {
|
|
|
|
const output = await processString("test {{ [test thing] }}", {
|
|
|
|
"test thing": 1
|
|
|
|
})
|
|
|
|
expect(output).toBe("test 1")
|
|
|
|
})
|
|
|
|
|
|
|
|
it("should convert to dot notation where required", async () => {
|
|
|
|
const output = await processString("test {{ test[0] }}", {
|
|
|
|
test: [2]
|
|
|
|
})
|
|
|
|
expect(output).toBe("test 2")
|
|
|
|
})
|
|
|
|
|
2021-01-20 14:32:15 +01:00
|
|
|
it("should be able to handle a property with a space in its name", async () => {
|
|
|
|
const output = await processString("hello my name is {{ person name }}", {
|
2021-01-19 19:44:29 +01:00
|
|
|
"person name": "Mike",
|
|
|
|
})
|
|
|
|
expect(output).toBe("hello my name is Mike")
|
|
|
|
})
|
|
|
|
|
2021-01-20 14:32:15 +01:00
|
|
|
it("should be able to handle an object with layers that requires escaping", async () => {
|
|
|
|
const output = await processString("testcase {{ testing.test case }}", {
|
2021-01-19 19:44:29 +01:00
|
|
|
testing: {
|
|
|
|
"test case": 1
|
|
|
|
}
|
|
|
|
})
|
|
|
|
expect(output).toBe("testcase 1")
|
|
|
|
})
|
|
|
|
})
|