Add forEachSelectors method

This commit is contained in:
Maxime Thirouin
2014-05-23 06:54:20 +02:00
parent baa6d2f4d7
commit f345cc4406
2 changed files with 32 additions and 0 deletions

View File

@@ -0,0 +1,24 @@
var tape = require("tape")
var forEachEls = require("../../../src/scripts/lib/foreach-selectors.js")
var cb = function(el) {
el.className = "modified"
}
tape("test forEachSelector", function(t) {
forEachEls(["html", "body"], cb)
t.equal(document.documentElement.className, "modified", "callback has been executed on first selector")
t.equal(document.body.className, "modified", "callback has been executed on first selector")
document.documentElement.className = ""
document.body.className = ""
forEachEls(["html", "body"], cb, null, document.documentElement)
t.equal(document.documentElement.className, "", "callback has not been executed on first selector when context is used")
t.equal(document.body.className, "modified", "callback has been executed on first selector when context is used")
t.end()
})