Example #1
0
    it("should return formatter from formatters dict when name is in formatters", () => {
      const f1 = tmpl.get_formatter("x", "@x", "$0.00", {x: "numeral"})
      expect(f1).to.be.equal(tmpl.DEFAULT_FORMATTERS.numeral)

      const f2 = tmpl.get_formatter("x", "@x", "%5.3f mu", {x: "printf"})
      expect(f2).to.be.equal(tmpl.DEFAULT_FORMATTERS.printf)

      const f3 = tmpl.get_formatter("x", "@x", "%m/%d/%Y", {x: "datetime"})
      expect(f3).to.be.equal(tmpl.DEFAULT_FORMATTERS.datetime)

      const custom = new CustomJSHover({code:"return format + ' ' + special_vars.special + ' ' + value"})
      const f4 = tmpl.get_formatter("x", "@x", "custom", {x: custom})
      expect(f4(3.123, "custom", {special: 10})).to.be.equal("custom 10 3.123")
    })
Example #2
0
 it("should return basic_formatter for null format", () => {
   const f = tmpl.get_formatter("x", "@x")
   expect(f).to.be.equal(tmpl.basic_formatter)
 })
Example #3
0
 it("should return numeral formatter for specs not in formatters dict", () => {
   const f = tmpl.get_formatter("x", "@x", "$0.00")
   expect(f).to.be.equal(tmpl.DEFAULT_FORMATTERS.numeral)
 })
Example #4
0
 expect(() => tmpl.get_formatter("x", "@x", "%5.3f mu", {x: "junk" as any})).to.throw(Error)