Skip to content

Commit d1a955c

Browse files
committed
fixed the double call of the callback function
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.
1 parent b8875ab commit d1a955c

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ function Xray() {
138138
if (!isUrl(url)) {
139139
debug('%j is not a url, finishing up', url);
140140
stream(obj, true);
141-
fn(null, pages);
141+
return fn(null, pages);
142142
}
143143

144144
stream(obj);

test/index.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,21 @@ describe('Xray()', function() {
247247

248248
});
249249

250+
it('should not call function twice when reaching the last page', function(done){
251+
this.timeout(10000);
252+
setTimeout(done, 9000);
253+
var timesCalled = 0;
254+
var x = Xray();
255+
256+
x('https://github.com/lapwinglabs/x-ray/watchers', '.follow-list-item', [{
257+
fullName: '.vcard-username'
258+
}]).paginate('.next_page@href').limit(10)
259+
(function(err, arr) {
260+
timesCalled++;
261+
assert.equal(1, timesCalled, 'callback was called more than once');
262+
});
263+
});
264+
250265
describe('.format()', function() {
251266
it('should support adding formatters', function() {
252267
// TODO

0 commit comments

Comments
 (0)