Jquery match plugin, works like .find() but throws errors on empty selectors or when the number of elements found doesn't match the second parameter (optional).
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
jQuery.fn.extend({ | |
match: function(selector, matched) { | |
var result = this.find(selector); | |
if (matched === undefined && !result.length) { | |
throw new Error("Not matched elements for selector" + selector); | |
} | |
if (matched !== undefined && result.length !== matched) { | |
throw new Error("Found elements don't match expected ones: " + | |
"expected: " + matched + | |
", found: " + result.length + | |
", selector: '" + selector + "'" | |
); | |
} | |
//all tests passed | |
return result; | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment