forked from ReactiveX/rxjs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Scheduler-spec.ts
72 lines (63 loc) · 1.7 KB
/
Scheduler-spec.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import { expect } from 'chai';
import { queueScheduler as queue } from 'rxjs';
import { QueueScheduler } from 'rxjs/internal/scheduler/QueueScheduler';
/** @test {Scheduler} */
describe('Scheduler.queue', () => {
it('should schedule things recursively', () => {
let call1 = false;
let call2 = false;
(queue as QueueScheduler).active = false;
queue.schedule(() => {
call1 = true;
queue.schedule(() => {
call2 = true;
});
});
expect(call1).to.be.true;
expect(call2).to.be.true;
});
it('should schedule things recursively via this.schedule', () => {
let call1 = false;
let call2 = false;
(queue as QueueScheduler).active = false;
queue.schedule(function (state) {
call1 = state.call1;
call2 = state.call2;
if (!call2) {
this.schedule({ call1: true, call2: true });
}
}, 0, { call1: true, call2: false });
expect(call1).to.be.true;
expect(call2).to.be.true;
});
it('should schedule things in the future too', (done: MochaDone) => {
let called = false;
queue.schedule(() => {
called = true;
}, 60);
setTimeout(() => {
expect(called).to.be.false;
}, 20);
setTimeout(() => {
expect(called).to.be.true;
done();
}, 100);
});
it('should be reusable after an error is thrown during execution', (done: MochaDone) => {
const results: number[] = [];
expect(() => {
queue.schedule(() => {
results.push(1);
});
queue.schedule(() => {
throw new Error('bad');
});
}).to.throw(Error, 'bad');
setTimeout(() => {
queue.schedule(() => {
results.push(2);
done();
});
}, 0);
});
});