Skip to content

Commit

Permalink
Make text(value) assign empty string for null/undefined
Browse files Browse the repository at this point in the history
Previously it would assign a literal string `"null"` for null, which
wasn't very useful.
  • Loading branch information
mislav committed Jun 16, 2014
1 parent 0ecb356 commit ed0eb87
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/zepto.js
Original file line number Diff line number Diff line change
Expand Up @@ -597,7 +597,7 @@ var Zepto = (function() {
(this.length > 0 ? this[0].textContent : null) :
this.each(function(idx){
var newText = funcArg(this, text, idx, this.textContent)
this.textContent = newText === undefined ? '' : ''+newText
this.textContent = newText == null ? '' : ''+newText
})
},
attr: function(name, value){
Expand Down
4 changes: 3 additions & 1 deletion test/zepto.html
Original file line number Diff line number Diff line change
Expand Up @@ -1631,7 +1631,8 @@ <h1>Zepto Core unit tests</h1>
t.assertEqual('', $('<h1/>').text())
t.assertEqual('', $('<h1/>').text('').text())
t.assertEqual('', $('<h1/>').text(undefined).text())
t.assertEqual('null', $('<h1/>').text(null).text())
t.assertEqual('', $('<h1/>').text(null).text())
t.assertEqual('false', $('<h1/>').text(false).text())
t.assertEqual('1', $('<h1/>').text(1).text())
t.assertEqual('<b>a</b>', $('<h1/>').text('<b>a</b>').text())

Expand Down Expand Up @@ -1666,6 +1667,7 @@ <h1>Zepto Core unit tests</h1>
t.assertEqual('HELLO 0', els[0].textContent)
t.assertEqual('', els[1].textContent)
t.assertEqual('WORLD 2', els[2].textContent)
t.assertEqual('', els[3].textContent)
},

testEmpty: function(t) {
Expand Down

0 comments on commit ed0eb87

Please sign in to comment.