Validate basic expressions
This commit is contained in:
parent
6e57be6380
commit
a4de97c419
|
@ -16,4 +16,60 @@ describe("hbs validator", () => {
|
|||
const result = validateHbsTemplate(text, validators)
|
||||
expect(result).toHaveLength(0)
|
||||
})
|
||||
|
||||
describe("basic expressions", () => {
|
||||
const validators = {
|
||||
fieldName: {},
|
||||
}
|
||||
|
||||
it("can validate valid expressions", () => {
|
||||
const text = "{{ fieldName }}"
|
||||
|
||||
const result = validateHbsTemplate(text, validators)
|
||||
expect(result).toHaveLength(0)
|
||||
})
|
||||
|
||||
it("can validate invalid expressions", () => {
|
||||
const text = "{{ anotherFieldName }}"
|
||||
|
||||
const result = validateHbsTemplate(text, validators)
|
||||
expect(result).toEqual([
|
||||
{
|
||||
from: 0,
|
||||
message: `"anotherFieldName" handler does not exist.`,
|
||||
severity: "warning",
|
||||
to: 22,
|
||||
},
|
||||
])
|
||||
})
|
||||
|
||||
it("can validate untrimmed invalid expressions", () => {
|
||||
const text = " {{ anotherFieldName }}"
|
||||
|
||||
const result = validateHbsTemplate(text, validators)
|
||||
expect(result).toEqual([
|
||||
{
|
||||
from: 4,
|
||||
message: `"anotherFieldName" handler does not exist.`,
|
||||
severity: "warning",
|
||||
to: 26,
|
||||
},
|
||||
])
|
||||
})
|
||||
|
||||
it("can validate invalid expressions between valid lines", () => {
|
||||
const text =
|
||||
"literal expression\nthe value is {{ anotherFieldName }}\nanother expression"
|
||||
|
||||
const result = validateHbsTemplate(text, validators)
|
||||
expect(result).toEqual([
|
||||
{
|
||||
from: 32,
|
||||
message: `"anotherFieldName" handler does not exist.`,
|
||||
severity: "warning",
|
||||
to: 54,
|
||||
},
|
||||
])
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
Loading…
Reference in New Issue