Files
pjax/tests/lib/foreach-els.js

61 lines
1.2 KiB
JavaScript
Raw Normal View History

2019-03-03 01:37:45 -05:00
var tape = require("tape");
2014-05-04 08:45:05 +02:00
2019-03-03 01:37:45 -05:00
var forEachEls = require("../../lib/foreach-els.js");
2014-05-04 08:45:05 +02:00
2019-03-03 01:37:45 -05:00
var div = document.createElement("div");
var span = document.createElement("span");
2014-05-04 08:45:05 +02:00
var cb = function(el) {
2019-03-03 01:37:45 -05:00
el.innerHTML = "boom";
};
2014-05-04 08:45:05 +02:00
tape("test forEachEls on one element", function(t) {
2019-03-03 01:37:45 -05:00
div.innerHTML = "div tag";
forEachEls(div, cb);
2014-05-04 08:45:05 +02:00
2019-03-03 01:37:45 -05:00
t.equal(div.innerHTML, "boom", "works correctly on one element");
t.end();
});
2014-05-04 08:45:05 +02:00
tape("test forEachEls on an array", function(t) {
2019-03-03 01:37:45 -05:00
div.innerHTML = "div tag";
span.innerHTML = "span tag";
2014-05-04 08:45:05 +02:00
2019-03-03 01:37:45 -05:00
forEachEls([div, span], cb);
2014-05-04 08:45:05 +02:00
2019-03-03 01:37:45 -05:00
t.equal(
div.innerHTML,
"boom",
"works correctly on the first element of the array"
);
t.equal(
span.innerHTML,
"boom",
"works correctly on the last element of the array"
);
2014-05-04 08:45:05 +02:00
2019-03-03 01:37:45 -05:00
t.end();
});
2014-05-04 08:45:05 +02:00
2014-07-15 17:42:38 +02:00
tape("test forEachEls on a NodeList", function(t) {
2019-03-03 01:37:45 -05:00
div.innerHTML = "div tag";
span.innerHTML = "span tag";
var frag = document.createDocumentFragment();
frag.appendChild(div);
frag.appendChild(span);
forEachEls(frag.childNodes, cb);
t.equal(
div.innerHTML,
"boom",
"works correctly on the first element of the document fragment"
);
t.equal(
span.innerHTML,
"boom",
"works correctly on the last element of the document fragment"
);
t.end();
});