Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
this improves readability somewhat (though it shouldn't be abused) again leveraging IIFEs; arguments passed in below and accepted under a different name using regular local variables instead of the arguments trick for QUnit to keep the IIFE's signature manageable
- Loading branch information
Showing
2 changed files
with
23 additions
and
16 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
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 |
---|---|---|
@@ -1,33 +1,40 @@ | ||
(function() { | ||
(function($) { | ||
|
||
var module = QUnit.module, | ||
asyncTest = QUnit.asyncTest, | ||
expect = QUnit.expect, | ||
strictEqual = QUnit.strictEqual, | ||
deepEqual = QUnit.deepEqual, | ||
start = QUnit.start; | ||
|
||
"use strict"; | ||
|
||
QUnit.module("contacts filtering"); | ||
module("contacts filtering"); | ||
|
||
QUnit.asyncTest("filtering by initials", function() { | ||
QUnit.expect(3); | ||
asyncTest("filtering by initials", function() { | ||
expect(3); | ||
|
||
var contacts = jQuery("ul.contacts"); | ||
var filterField = jQuery("input[type=search]"); | ||
var contacts = $("ul.contacts"); | ||
var filterField = $("input[type=search]"); | ||
|
||
QUnit.strictEqual(filterField.length, 1); | ||
strictEqual(filterField.length, 1); | ||
var names = extractNames(contacts.find("li:visible")); | ||
QUnit.deepEqual(names, ["Jake Archibald", "Christian Heilmann", | ||
deepEqual(names, ["Jake Archibald", "Christian Heilmann", | ||
"John Resig", "Nicholas Zakas"]); | ||
|
||
filterField.val("J").trigger("keyup"); | ||
setTimeout(function() { | ||
var names = extractNames(contacts.find("li:visible")); | ||
QUnit.deepEqual(names, ["Jake Archibald", "John Resig"]); | ||
QUnit.start(); | ||
deepEqual(names, ["Jake Archibald", "John Resig"]); | ||
start(); | ||
}, 500); | ||
}); | ||
|
||
function extractNames(items) { | ||
var names = items.map(function(i, node) { | ||
return jQuery(".p-name", node).text(); | ||
return $(".p-name", node).text(); | ||
}); | ||
return Array.prototype.slice.call(names); | ||
} | ||
|
||
}()); | ||
}(jQuery)); |