Skip to content

Commit

Permalink
Merge pull request #177 from davidchambers/propagate-errors
Browse files Browse the repository at this point in the history
propagate syntax errors caused by invalid selectors
  • Loading branch information
matthewmueller committed Mar 31, 2013
2 parents 20c108d + 504269a commit b30a081
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
7 changes: 1 addition & 6 deletions lib/api/traversing.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,7 @@ var _ = require('underscore'),
isTag = utils.isTag;

var find = exports.find = function(selector) {
try {
var elem = select(selector, [].slice.call(this.children()));
return this.make(elem);
} catch(e) {
return this.make([]);
}
return this.make(select(selector, [].slice.call(this.children())));
};

var parent = exports.parent = function(elem) {
Expand Down
8 changes: 8 additions & 0 deletions test/api.traversing.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,14 @@ describe('$(...)', function() {
expect($('#fruits').find('li')).to.have.length(0);
});

it('should throw a SyntaxError if given an invalid selector', function() {
expect(function() {
$('#fruits').find(':bah');
}).to.throwException(function(err) {
expect(err).to.be.a(SyntaxError);
});
});

});

describe('.children', function() {
Expand Down

0 comments on commit b30a081

Please sign in to comment.