Skip to content

Commit

Permalink
test: add unit test for helper on unresolved template string
Browse files Browse the repository at this point in the history
  • Loading branch information
shumailxyz committed Jun 26, 2023
1 parent bdf0190 commit 8dbff94
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
8 changes: 4 additions & 4 deletions core/src/template-string/functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -512,13 +512,13 @@ export function callHelperFunction({

// do not apply helper function for an unresolved template string
if (maybeTemplateString(value)) {
const _error = new TemplateStringError(`Function '${functionName}' cannot be applied on unresolved string`, {
functionName,
text,
})
if (allowPartial) {
return { resolved: "${" + text + "}" }
} else {
const _error = new TemplateStringError(`Function '${functionName}' cannot be applied on unresolved string`, {
functionName,
text,
})
return { _error }
}
}
Expand Down
7 changes: 7 additions & 0 deletions core/test/unit/src/template-string.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1053,6 +1053,13 @@ describe("resolveTemplateString", () => {
})
})

it("does not apply helper function on unresolved template string and returns string as-is, when allowPartial=true", () => {
const res = resolveTemplateString("${base64Encode('${environment.namespace}')}", new TestContext({}), {
allowPartial: true,
})
expect(res).to.equal("${base64Encode('${environment.namespace}')}")
})

context("concat", () => {
it("allows empty strings", () => {
const res = resolveTemplateString("${concat('', '')}", new TestContext({}))
Expand Down

0 comments on commit 8dbff94

Please sign in to comment.