Skip to content

Commit

Permalink
Render booleans as empty strings
Browse files Browse the repository at this point in the history
  • Loading branch information
fitbitBruce committed Jun 10, 2016
1 parent 8ee7592 commit c98f663
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 2 deletions.
2 changes: 1 addition & 1 deletion mithril.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
18 changes: 18 additions & 0 deletions test/mithril.render.js
Original file line number Diff line number Diff line change
Expand Up @@ -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")]))
Expand Down
20 changes: 19 additions & 1 deletion tests/mithril-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -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" })
Expand Down Expand Up @@ -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")]))
Expand Down

0 comments on commit c98f663

Please sign in to comment.