Skip to content

Commit

Permalink
Add tests for each()
Browse files Browse the repository at this point in the history
  • Loading branch information
townxelliot committed Aug 27, 2013
1 parent 9185e2d commit f2f0811
Showing 1 changed file with 68 additions and 0 deletions.
68 changes: 68 additions & 0 deletions test/each.test.js
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);
});
});

0 comments on commit f2f0811

Please sign in to comment.