1 import createEventManager from '../../lib/eventManager/eventManager';
3 const mockApi = (responses) => {
5 const cb = async () => {
6 const response = responses[i++];
7 if (response instanceof Error) {
12 return jasmine.createSpy('mockApi').and.callFake(cb);
16 * TODO: More tests when https://stackoverflow.com/a/50785284 exists
18 describe('event manager', () => {
19 it('should call more and not finish until it is done', async () => {
21 { EventID: '1', More: 1 },
22 { EventID: '2', More: 1 },
23 { EventID: '3', More: 1 },
24 { EventID: '4', More: 1 },
25 { EventID: '5', More: 1 },
26 { EventID: '6', More: 0 },
27 { EventID: '6', More: 0 },
30 const eventManager = createEventManager({
35 const onSuccess = jasmine.createSpy();
36 const unsubscribe = eventManager.subscribe(onSuccess);
40 await eventManager.call();
42 expect(api.calls.all().length).toEqual(6);
43 expect(onSuccess.calls.all().length).toEqual(6);
45 await eventManager.call();
47 expect(api.calls.all().length, 7);
48 expect(onSuccess.calls.all().length, 7);