mirror of
https://github.com/twitter/twemoji.git
synced 2024-06-15 03:35:16 +00:00
Merge c331390895
into 39a091da4b
This commit is contained in:
commit
32a68527f9
15
test.js
15
test.js
@ -146,10 +146,8 @@ wru.test([{
|
|||||||
div = document.createElement('div');
|
div = document.createElement('div');
|
||||||
div.appendChild(document.createTextNode('I \u2764\uFE0E emoji!'));
|
div.appendChild(document.createTextNode('I \u2764\uFE0E emoji!'));
|
||||||
twemoji.parse(div);
|
twemoji.parse(div);
|
||||||
wru.assert('default parsing created 3 nodes anyway', div.childNodes.length === 3);
|
wru.assert('default parsing created 1 node', div.childNodes.length === 1);
|
||||||
wru.assert('first child is the expected one', div.removeChild(div.firstChild).nodeValue === 'I ');
|
wru.assert('first child is the expected one', div.removeChild(div.firstChild).nodeValue === 'I \u2764\uFE0E emoji!');
|
||||||
wru.assert('emoji child is unchanged', div.removeChild(div.firstChild).nodeValue === '\u2764\uFE0E');
|
|
||||||
wru.assert('last child is the expected one', div.removeChild(div.firstChild).nodeValue === ' emoji!');
|
|
||||||
}
|
}
|
||||||
},{
|
},{
|
||||||
name: 'DOM parsing + size',
|
name: 'DOM parsing + size',
|
||||||
@ -421,4 +419,13 @@ wru.test([{
|
|||||||
wru.assert('correct length', div.getElementsByTagName('img').length === 0);
|
wru.assert('correct length', div.getElementsByTagName('img').length === 0);
|
||||||
wru.assert('expected html', div.innerHTML === '"\u2b1c\uFE0E"');
|
wru.assert('expected html', div.innerHTML === '"\u2b1c\uFE0E"');
|
||||||
}
|
}
|
||||||
|
},{
|
||||||
|
name: 'callback can return false and prevent changes',
|
||||||
|
test: function () {
|
||||||
|
var div = document.createElement('div');
|
||||||
|
var text = document.createTextNode('I \u2764 emoji!');
|
||||||
|
div.appendChild(text);
|
||||||
|
twemoji.parse(div, function() { return false; });
|
||||||
|
wru.assert('text node is preserved', div.firstChild === text);
|
||||||
|
}
|
||||||
}]);
|
}]);
|
@ -369,10 +369,10 @@ var twemoji = (function (
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
fragment.appendChild(img || createText(alt));
|
fragment.appendChild(img || createText(alt));
|
||||||
img = null;
|
|
||||||
}
|
}
|
||||||
// is there actually anything to replace in here ?
|
// is there actually anything to replace in here ?
|
||||||
if (0 < i) {
|
if (img) {
|
||||||
|
img = null;
|
||||||
// any text left to be added ?
|
// any text left to be added ?
|
||||||
if (i < text.length) {
|
if (i < text.length) {
|
||||||
fragment.appendChild(
|
fragment.appendChild(
|
||||||
|
Loading…
Reference in New Issue
Block a user