forked from intel/appframework
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9185e2d
commit f2f0811
Showing
1 changed file
with
68 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
var should = require("chai").should(); | ||
var domHelper = require("./dom.helper"); | ||
|
||
describe("each", function () { | ||
beforeEach(function () { | ||
domHelper( | ||
"<div data-alpha=\"a\"></div>" + | ||
"<div data-alpha=\"b\"></div>" + | ||
"<div data-alpha=\"c\"></div>" | ||
); | ||
}); | ||
|
||
it("should iterate over members of an af collection", function () { | ||
var expected = "a,b,c"; | ||
|
||
var collected = []; | ||
|
||
var count = 0; | ||
|
||
$("div").each(function (index, item) { | ||
count += 1; | ||
collected.push(item.getAttribute("data-alpha")); | ||
}); | ||
|
||
var actual = collected.join(","); | ||
|
||
actual.should.equal(expected); | ||
count.should.equal(3); | ||
}); | ||
|
||
it("should iterate over members of an af collection passed to $.each", function () { | ||
var expected = "a,b,c"; | ||
|
||
var collected = []; | ||
|
||
var count = 0; | ||
|
||
$.each($("div"), function (index, item) { | ||
count += 1; | ||
|
||
// work around for bug #348 | ||
if (typeof item === "object") { | ||
collected.push(item.getAttribute("data-alpha")); | ||
} | ||
}); | ||
|
||
var actual = collected.join(","); | ||
|
||
actual.should.equal(expected); | ||
|
||
// bug https://github.com/01org/appframework/issues/348 | ||
// count.should.equal(3); | ||
}); | ||
|
||
it("should iterate over an array", function () { | ||
var arr = ["a", "b", "c"]; | ||
|
||
var actual = ""; | ||
|
||
$.each(arr, function (index, item) { | ||
actual += item; | ||
}); | ||
|
||
var expected = "abc"; | ||
|
||
actual.should.equal(expected); | ||
}); | ||
}); |