pon-shared-pon.universe.frontend.shared.componentlibrary
Version:
shared components for Pon Universe
40 lines (35 loc) • 1.34 kB
JavaScript
import ParseDictionaryTokens from "./pu-filter-parse-tokens";
describe("ParseDictionaryTokens.js", () => {
it("returns an empty string when no value is given", () => {
expect(ParseDictionaryTokens("")).toBe("");
expect(ParseDictionaryTokens("abc")).not.toBe("");
});
it("returns the given value when no tokens are given", () => {
expect(ParseDictionaryTokens("test value")).toBe("test value");
});
it("replaces placeholders in the given string with corresponding values in the tokens", () => {
expect(
ParseDictionaryTokens(
"My name is {name}, I am {age} years old. And still my name is {name}.",
{
tokens: {
name: "Paul",
age: "27"
}
}
)
).toBe("My name is Paul, I am 27 years old. And still my name is Paul.");
});
it("encodes all token characters as HTML, when that option is set", () => {
expect(
ParseDictionaryTokens("This is some dangerous {html}.", {
tokens: {
html: "<script>eval evil</script>"
},
encodeHTML: true
})
).toBe(
"This is some dangerous <script>eval evil</script>."
);
});
});