UNPKG

pon-shared-pon.universe.frontend.shared.componentlibrary

Version:

shared components for Pon Universe

40 lines (35 loc) 1.34 kB
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 &#60;&#115;&#99;&#114;&#105;&#112;&#116;&#62;&#101;&#118;&#97;&#108;&#32;&#101;&#118;&#105;&#108;&#60;&#47;&#115;&#99;&#114;&#105;&#112;&#116;&#62;." ); }); });