Skip to content

Commit

Permalink
failed iterator
Browse files Browse the repository at this point in the history
  • Loading branch information
cdmbase committed Aug 24, 2017
1 parent 249b666 commit 3fc1cb6
Showing 1 changed file with 35 additions and 1 deletion.
36 changes: 35 additions & 1 deletion src/__tests__/async-iterator.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,39 @@ describe('AsyncIterator', () => {
});
ps.publish(eventName, { test: true });
});
});

it('should not trigger event on asyncIterator already returned', done => {
const eventName = 'test5';
const ps = new NatsPubSub({ logger });
const iterator = ps.asyncIterator(eventName);

iterator.next().then(result => {
customLogger.trace('result: (%j)', result);

try {
expect(result).toBeDefined();
expect(result.value).toBeDefined();
expect(result.done).toBeFalsy();
} catch (e) {
done.fail(e);
}
});

ps.publish(eventName, { test: true });

iterator.next().then(result => {
customLogger.trace('result: (%j)', result);
try {
expect(result).toBeDefined();
expect(result.value).not.toBeDefined();
expect(result.done).toBeTruthy();
done();
} catch (e) {
done.fail(e);
}
});

iterator.return();
ps.publish(eventName, { test: true });
});
});

0 comments on commit 3fc1cb6

Please sign in to comment.