Render booleans as empty strings

This commit is contained in:
Bruce Lewis 2016-06-10 11:00:56 -04:00
parent 8ee75924c8
commit c98f663653
3 changed files with 38 additions and 2 deletions

View file

@ -188,7 +188,7 @@
// value of Console.log in some versions of Firefox (behavior depends on
// version)
try {
if (data != null && data.toString() != null) return data
if (typeof data !== "boolean" && data != null && data.toString() != null) return data
} catch (e) {
// silently ignore errors
}

View file

@ -57,6 +57,24 @@ describe("m.render()", function () {
expect(root.childNodes[0].childNodes[0].nodeValue).to.equal("")
})
it("renders `null` body to empty string", function () {
var root = mock.document.createElement("div")
m.render(root, m("div", [null]))
expect(root.childNodes[0].childNodes[0].nodeValue).to.equal("")
})
it("renders `true` body to empty string", function () {
var root = mock.document.createElement("div")
m.render(root, m("div", [true]))
expect(root.childNodes[0].childNodes[0].nodeValue).to.equal("")
})
it("renders `false` body to empty string", function () {
var root = mock.document.createElement("div")
m.render(root, m("div", [false]))
expect(root.childNodes[0].childNodes[0].nodeValue).to.equal("")
})
it("uses the W3C URI as default namespace for SVG children", function () {
var root = mock.document.createElement("div")
m.render(root, m("svg", [m("g")]))

View file

@ -11,7 +11,7 @@
test(function () { return m(".foo").attrs.className === "foo" })
test(function () { return m("[title=bar]").tag === "div" })
test(function () { return m("[title=bar]").attrs.title === "bar" })
test(function () { return m("[empty]").attrs.empty === "" })
test(function () { return m("[empty]").attrs.empty === true })
test(function () { return m("[title=\'bar\']").attrs.title === "bar" })
test(function () { return m("[title=\"bar\"]").attrs.title === "bar" })
test(function () { return m("div", "test").children[0] === "test" })
@ -1750,6 +1750,24 @@
return root.childNodes[0].childNodes[0].nodeValue === ""
})
test(function () {
var root = mock.document.createElement("div")
m.render(root, m("div", [null]))
return root.childNodes[0].childNodes[0].nodeValue === ""
})
test(function () {
var root = mock.document.createElement("div")
m.render(root, m("div", [true]))
return root.childNodes[0].childNodes[0].nodeValue === ""
})
test(function () {
var root = mock.document.createElement("div")
m.render(root, m("div", [false]))
return root.childNodes[0].childNodes[0].nodeValue === ""
})
test(function () {
var root = mock.document.createElement("div")
m.render(root, m("svg", [m("g")]))