Add a `.expectOne` method to jQuery objects.

It asserts that the result set is exactly one element.

(imported from commit c78ff131deb4a13c65c2a68e4b8e09279ece3ea0)
This commit is contained in:
Kevin Mehall 2013-09-03 16:11:55 -04:00
parent 2f8bd32ef8
commit 9428f40422
1 changed files with 9 additions and 0 deletions

View File

@ -315,6 +315,15 @@ exports.enforce_arity = function util_enforce_arity(func) {
};
};
if (typeof $ !== 'undefined') {
$.fn.expectOne = function () {
if (blueslip && this.length !== 1) {
blueslip.error("Expected one element in jQuery set, " + this.length + " found");
}
return this;
};
}
return exports;
}());
if (typeof module !== 'undefined') {