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

46 lines
1.2 KiB
JavaScript
Raw Normal View History

2014-05-04 08:45:05 +02:00
var tape = require("tape")
2014-10-14 08:23:56 +02:00
var forEachEls = require("../../lib/foreach-els.js")
2014-05-04 08:45:05 +02:00
var div = document.createElement("div")
var span = document.createElement("span")
var cb = function(el) {
el.innerHTML = "boom"
}
tape("test forEachEls on one element", function(t) {
div.innerHTML = "div tag"
forEachEls(div, cb)
t.equal(div.innerHTML, "boom", "works correctly on one element")
t.end()
})
tape("test forEachEls on an array", function(t) {
div.innerHTML = "div tag"
span.innerHTML = "span tag"
forEachEls([div, span], cb)
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")
t.end()
})
2014-07-15 17:42:38 +02:00
tape("test forEachEls on a NodeList", function(t) {
2014-05-04 08:45:05 +02: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()
})