Skip to content

Commit

Permalink
test(take): test for recursive case of take operator
Browse files Browse the repository at this point in the history
  • Loading branch information
midnight-wonderer authored and staltz committed Dec 22, 2016
1 parent d408290 commit e83b7b7
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions tests/operator/take.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,40 @@ describe('Stream.prototype.take', () => {
},
});
});

it('should terminate properly when "next" function recursively calls itself', (done: any) => {
const producer = {
start: (listener: any) => {
this.listener = listener;
listener.next(1);
},
_n: (value: any) => {
const listener = this.listener;
listener && listener.next(value);
},
_e: (value: string) => {
const listener = this.listener;
listener && listener.error(value);
},
stop: () => this.listener = null,
listener: null
};
const stream = xs.create(producer);

let nextCount = 0;
stream.take(1).addListener({
next: (x: number) => {
nextCount++;
if (nextCount > 1) {
producer._e('next should not be called more than once');
} else {
producer._n(x);
}
},
error: (err: any) => done(err),
complete: () => {
done();
}
});
});
});

0 comments on commit e83b7b7

Please sign in to comment.