Skip to content

Commit

Permalink
fixed the double call of the callback function
Browse files Browse the repository at this point in the history
When reaching the last page the callback function is called twice.
This fixes #53

Added a test but it’s a bit messy because it’s a negative test and I am
not a javascript dev so I hope someone can refactor it in a more
elegant way.
  • Loading branch information
cosminonea committed Jun 24, 2015
1 parent b8875ab commit d1a955c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ function Xray() {
if (!isUrl(url)) {
debug('%j is not a url, finishing up', url);
stream(obj, true);
fn(null, pages);
return fn(null, pages);
}

stream(obj);
Expand Down
15 changes: 15 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,21 @@ describe('Xray()', function() {

});

it('should not call function twice when reaching the last page', function(done){
this.timeout(10000);
setTimeout(done, 9000);
var timesCalled = 0;
var x = Xray();

x('https://github.com/lapwinglabs/x-ray/watchers', '.follow-list-item', [{
fullName: '.vcard-username'
}]).paginate('.next_page@href').limit(10)
(function(err, arr) {
timesCalled++;
assert.equal(1, timesCalled, 'callback was called more than once');
});
});

describe('.format()', function() {
it('should support adding formatters', function() {
// TODO
Expand Down

0 comments on commit d1a955c

Please sign in to comment.