Skip to content

Commit

Permalink
Avoid undefined in textContent
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinpschaaf committed May 20, 2015
1 parent a802228 commit cdecff4
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
4 changes: 4 additions & 0 deletions src/standard/effects.html
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,10 @@
if (property === 'className') {
value = this._scopeElementClass(node, value);
}
// Some browsers serialize `undefined` textContent to `"undefined"`
if (property === 'textContent') {
value = value == undefined ? '' : value;
}
return node[property] = value;
}
}
Expand Down
3 changes: 2 additions & 1 deletion test/unit/bind-elements.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
custom-event-object-value="{{customEventObject.value::change}}">
Test
</div>
<span id="{{boundId}}"></span>
<span id="boundText">{{text}}</span>
<span idtest id="{{boundId}}"></span>
</template>
<script>
Polymer({
Expand Down
23 changes: 22 additions & 1 deletion test/unit/bind.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,28 @@
});

test('id is bindable', function() {
assert.equal(Polymer.dom(el.root).querySelector('span').id, 'span', 'id bound to <span> not found');
assert.equal(Polymer.dom(el.root).querySelector('span[idtest]').id, 'span', 'id bound to <span> not found');
});

test('textContent binding updates', function() {
el.text = 'this is a test';
assert.equal(el.$.boundText.textContent, 'this is a test', 'Value not propagated to textContent');
});

test('textContent binding to undefined is empty string', function() {
el.text = 'this is a test';
el.text = undefined;
assert.equal(el.$.boundText.textContent, '', 'undefined bound to textContent should be empty string');
});

test('textContent binding to null is empty string', function() {
el.text = null;
assert.equal(el.$.boundText.textContent, '', 'null bound to textContent should be empty string');
});

test('textContent binding to zero is empty correct', function() {
el.text = 0;
assert.equal(el.$.boundText.textContent, '0', 'zero bound to textContent should be empty string');
});

test('camel-case binding updates', function() {
Expand Down

0 comments on commit cdecff4

Please sign in to comment.