Update string-templates tests
This commit is contained in:
parent
4e200d0def
commit
ac75c3cd65
|
@ -4,19 +4,19 @@ const {
|
|||
isValid,
|
||||
makePropSafe,
|
||||
getManifest,
|
||||
} = require("../src/index")
|
||||
} = require("../src/index.cjs")
|
||||
|
||||
describe("Test that the string processing works correctly", () => {
|
||||
it("should process a basic template string", async () => {
|
||||
const output = await processString("templating is {{ adjective }}", {
|
||||
adjective: "easy"
|
||||
adjective: "easy",
|
||||
})
|
||||
expect(output).toBe("templating is easy")
|
||||
})
|
||||
|
||||
it("should process a literal template", async () => {
|
||||
const output = await processString("derp is {{{ adjective }}}", {
|
||||
adjective: "derp"
|
||||
adjective: "derp",
|
||||
})
|
||||
expect(output).toBe("derp is derp")
|
||||
})
|
||||
|
@ -42,23 +42,29 @@ describe("Test that the string processing works correctly", () => {
|
|||
|
||||
describe("Test that the object processing works correctly", () => {
|
||||
it("should be able to process an object with some template strings", async () => {
|
||||
const output = await processObject({
|
||||
const output = await processObject(
|
||||
{
|
||||
first: "thing is {{ adjective }}",
|
||||
second: "thing is bad",
|
||||
third: "we are {{ adjective }} {{ noun }}",
|
||||
}, {
|
||||
},
|
||||
{
|
||||
adjective: "easy",
|
||||
noun: "people",
|
||||
})
|
||||
}
|
||||
)
|
||||
expect(output.first).toBe("thing is easy")
|
||||
expect(output.second).toBe("thing is bad")
|
||||
expect(output.third).toBe("we are easy people")
|
||||
})
|
||||
|
||||
it("should be able to handle arrays of string templates", async () => {
|
||||
const output = await processObject(["first {{ noun }}", "second {{ noun }}"], {
|
||||
noun: "person"
|
||||
})
|
||||
const output = await processObject(
|
||||
["first {{ noun }}", "second {{ noun }}"],
|
||||
{
|
||||
noun: "person",
|
||||
}
|
||||
)
|
||||
expect(output[0]).toBe("first person")
|
||||
expect(output[1]).toBe("second person")
|
||||
})
|
||||
|
@ -107,6 +113,8 @@ describe("check manifest", () => {
|
|||
it("should be able to retrieve the manifest", () => {
|
||||
const manifest = getManifest()
|
||||
expect(manifest.math).not.toBeNull()
|
||||
expect(manifest.math.abs.description).toBe("<p>Return the magnitude of <code>a</code>.</p>\n")
|
||||
expect(manifest.math.abs.description).toBe(
|
||||
"<p>Return the magnitude of <code>a</code>.</p>\n"
|
||||
)
|
||||
})
|
||||
})
|
|
@ -1,18 +1,16 @@
|
|||
const {
|
||||
processString,
|
||||
} = require("../src/index")
|
||||
const { processString } = require("../src/index.cjs")
|
||||
|
||||
describe("Handling context properties with spaces in their name", () => {
|
||||
it("should allow through literal specifiers", async () => {
|
||||
const output = await processString("test {{ [one thing] }}", {
|
||||
"one thing": 1
|
||||
"one thing": 1,
|
||||
})
|
||||
expect(output).toBe("test 1")
|
||||
})
|
||||
|
||||
it("should convert to dot notation where required", async () => {
|
||||
const output = await processString("test {{ one[0] }}", {
|
||||
one: [2]
|
||||
one: [2],
|
||||
})
|
||||
expect(output).toBe("test 2")
|
||||
})
|
||||
|
@ -27,8 +25,8 @@ describe("Handling context properties with spaces in their name", () => {
|
|||
it("should be able to handle an object with layers that requires escaping", async () => {
|
||||
const output = await processString("testcase {{ thing.[one case] }}", {
|
||||
thing: {
|
||||
"one case": 1
|
||||
}
|
||||
"one case": 1,
|
||||
},
|
||||
})
|
||||
expect(output).toBe("testcase 1")
|
||||
})
|
||||
|
@ -39,21 +37,22 @@ describe("attempt some complex problems", () => {
|
|||
const context = {
|
||||
"New Repeater": {
|
||||
"Get Actors": {
|
||||
"first_name": "Bob",
|
||||
"last_name": "Bobert"
|
||||
first_name: "Bob",
|
||||
last_name: "Bobert",
|
||||
},
|
||||
},
|
||||
}
|
||||
const hbs = "{{ [New Repeater].[Get Actors].[first_name] }} {{ [New Repeater].[Get Actors].[last_name] }}"
|
||||
const hbs =
|
||||
"{{ [New Repeater].[Get Actors].[first_name] }} {{ [New Repeater].[Get Actors].[last_name] }}"
|
||||
const output = await processString(hbs, context)
|
||||
expect(output).toBe("Bob Bobert")
|
||||
})
|
||||
|
||||
it("should be able to process an odd string produced by builder", async () => {
|
||||
const context = {
|
||||
"c306d140d7e854f388bae056db380a0eb": {
|
||||
c306d140d7e854f388bae056db380a0eb: {
|
||||
"one prop": "test",
|
||||
}
|
||||
},
|
||||
}
|
||||
const hbs = "null{{ [c306d140d7e854f388bae056db380a0eb].[one prop] }}"
|
||||
const output = await processString(hbs, context)
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
const { processString, processObject, isValid } = require("../src/index")
|
||||
const { processString, processObject, isValid } = require("../src/index.cjs")
|
||||
|
||||
describe("test the custom helpers we have applied", () => {
|
||||
it("should be able to use the object helper", async () => {
|
||||
|
|
|
@ -1,9 +1,8 @@
|
|||
const { processString } = require("../src/index")
|
||||
const { processString } = require("../src/index.cjs")
|
||||
|
||||
describe("specific test case for whether or not full app template can still be rendered", () => {
|
||||
it("should be able to render the app template", async () => {
|
||||
const template =
|
||||
`<!doctype html>
|
||||
const template = `<!doctype html>
|
||||
<html>
|
||||
<head>
|
||||
{{{head}}}
|
||||
|
@ -16,7 +15,7 @@ describe("specific test case for whether or not full app template can still be r
|
|||
const context = {
|
||||
appId: "App1",
|
||||
head: "<title>App</title>",
|
||||
body: "<body><p>App things</p></body>"
|
||||
body: "<body><p>App things</p></body>",
|
||||
}
|
||||
const output = await processString(template, context)
|
||||
expect(output).toBe(`<!doctype html>
|
||||
|
|
Loading…
Reference in New Issue