Skip to content

Commit

Permalink
If queue an undefined value, should skip it
Browse files Browse the repository at this point in the history
  • Loading branch information
jasondeveloper-1099 committed Nov 14, 2014
1 parent de86a85 commit 0780ab6
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/crawler.js
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ Crawler.prototype.queue = function queue (options) {
self._pushToQueue({
uri: options
});
} else {
} else if (options) {
self._pushToQueue(options);
}
};
Expand Down
19 changes: 17 additions & 2 deletions tests/uriOption.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@

var Crawler = require('../lib/crawler');
var expect = require('chai').expect;
var sinon = require('sinon');
var httpbinHost = 'localhost:8000';
var c;
var c, spy;

describe('Uri Options', function() {
afterEach(function() {
c = {};
c = spy = {};
});
it('should work if uri is a function', function(done) {
var statusCode = 200;
Expand Down Expand Up @@ -47,4 +48,18 @@ describe('Uri Options', function() {
uri: googleSearch('cheese')
});
});
it('should skip if the uri is undefined or an empty string', function(done) {
c = new Crawler({
onDrain: function() {
expect(spy.calledOnce).to.be.true;
done();
},
callback: function(error, result) {
expect(typeof result.statusCode).to.equal('number');
expect(result.statusCode).to.equal(200);
}
});
spy = sinon.spy(c, '_pushToQueue');
c.queue([undefined, 'http://'+httpbinHost]);
});
});

0 comments on commit 0780ab6

Please sign in to comment.