forked from angular/angular
-
Notifications
You must be signed in to change notification settings - Fork 85
/
Copy pathrxjs.Observable.audit.spec.ts
85 lines (76 loc) · 2.79 KB
/
rxjs.Observable.audit.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
73
74
75
76
77
78
79
80
81
82
83
84
85
/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
import {interval, Observable} from 'rxjs';
import {audit, auditTime} from 'rxjs/operators';
import {asyncTest} from '../test-util';
xdescribe('Observable.audit', () => {
let log: any[];
let observable1: Observable<any>;
beforeEach(() => {
log = [];
});
it('audit func callback should run in the correct zone', asyncTest((done: any) => {
const constructorZone1: Zone = Zone.current.fork({name: 'Constructor Zone1'});
const subscriptionZone: Zone = Zone.current.fork({name: 'Subscription Zone'});
observable1 = constructorZone1.run(() => {
const source = interval(100);
return source.pipe(audit(ev => {
expect(Zone.current.name).toEqual(constructorZone1.name);
return interval(150);
}));
});
subscriptionZone.run(() => {
const subscriber = observable1.subscribe(
(result: any) => {
expect(Zone.current.name).toEqual(subscriptionZone.name);
log.push(result);
if (result >= 3) {
subscriber.unsubscribe();
}
},
() => {
fail('should not call error');
},
() => {
log.push('completed');
expect(Zone.current.name).toEqual(subscriptionZone.name);
expect(log).toEqual([1, 3, 'completed']);
done();
});
});
expect(log).toEqual([]);
}, Zone.root));
xit('auditTime func callback should run in the correct zone', asyncTest((done: any) => {
const constructorZone1: Zone = Zone.current.fork({name: 'Constructor Zone1'});
const subscriptionZone: Zone = Zone.current.fork({name: 'Subscription Zone'});
observable1 = constructorZone1.run(() => {
const source = interval(100);
return source.pipe(auditTime(360));
});
subscriptionZone.run(() => {
const subscriber = observable1.subscribe(
(result: any) => {
expect(Zone.current.name).toEqual(subscriptionZone.name);
log.push(result);
if (result >= 7) {
subscriber.unsubscribe();
}
},
() => {
fail('should not call error');
},
() => {
log.push('completed');
expect(Zone.current.name).toEqual(subscriptionZone.name);
expect(log).toEqual([3, 7, 'completed']);
done();
});
});
expect(log).toEqual([]);
}, Zone.root));
});