Is there any built in support in jQuery for basic assertion checking, primarily of things like \'expected number of returned elements\'.
For instance I may have a simple
Enhancements to Tomalak’s answer: throw the error to halt execution, include the offending selector and add the assertSingle
variant.
$.fn.assertSize = function(size) {
if (this.length != size) {
throw "Expected " + size + " elements, but selector '" + this.selector + "' found " + this.length + ".";
}
return this;
};
$.fn.assertSingle = function() { return this.assertSize(1); };