1
+ /* globals describe, it, expect, expectObservable, hot */
2
+ var Rx = require ( '../../dist/cjs/Rx' ) ;
3
+
4
+ describe ( 'Observable.prototype.every()' , function ( ) {
5
+ function truePredicate ( x ) {
6
+ return true ;
7
+ }
8
+
9
+ function predicate ( x ) {
10
+ return x % 5 === 0 ;
11
+ }
12
+
13
+ it ( 'should emit true if source is empty' , function ( ) {
14
+ var source = hot ( '-----|' ) ;
15
+ var expected = '-----(x|)' ;
16
+
17
+ expectObservable ( source . every ( predicate ) ) . toBe ( expected , { x : true } ) ;
18
+ } ) ;
19
+
20
+ it ( 'should emit false if single source of element does not match with predicate' , function ( ) {
21
+ var source = hot ( '--a--|' ) ;
22
+ var expected = '--(x|)' ;
23
+
24
+ expectObservable ( source . every ( predicate ) ) . toBe ( expected , { x : false } ) ;
25
+ } ) ;
26
+
27
+ it ( 'should emit false if none of element does not match with predicate' , function ( ) {
28
+ var source = hot ( '--a--b--c--d--e--|' ) ;
29
+ var expected = '--(x|)' ;
30
+
31
+ expectObservable ( source . every ( predicate ) ) . toBe ( expected , { x : false } ) ;
32
+ } ) ;
33
+
34
+ it ( 'should return false if only some of element matches with predicate' , function ( ) {
35
+ var source = hot ( '--a--b--c--d--e--|' , { a : 5 , b : 10 , c : 15 } ) ;
36
+ var expected = '-----------(x|)' ;
37
+
38
+ expectObservable ( source . every ( predicate ) ) . toBe ( expected , { x : false } ) ;
39
+ } ) ;
40
+
41
+ it ( 'should emit true if single source element match with predicate' , function ( ) {
42
+ var source = hot ( '--a--|' , { a : 5 } ) ;
43
+ var expected = '-----(x|)' ;
44
+
45
+ expectObservable ( source . every ( predicate ) ) . toBe ( expected , { x : true } ) ;
46
+ } ) ;
47
+
48
+ it ( 'should emit true if all source element matches with predicate' , function ( ) {
49
+ var source = hot ( '--a--b--c--d--e--|' , { a : 5 , b : 10 , c : 15 , d : 20 , e : 25 } ) ;
50
+ var expected = '-----------------(x|)' ;
51
+
52
+ expectObservable ( source . every ( predicate ) ) . toBe ( expected , { x : true } ) ;
53
+ } ) ;
54
+
55
+ it ( 'should raise error if source raises error' , function ( ) {
56
+ var source = hot ( '--#' ) ;
57
+ var expected = '--#' ;
58
+
59
+ expectObservable ( source . every ( truePredicate ) ) . toBe ( expected ) ;
60
+ } ) ;
61
+
62
+ it ( 'should not completes if source never emits' , function ( ) {
63
+ var expected = '-' ;
64
+
65
+ expectObservable ( Rx . Observable . never ( ) . every ( truePredicate ) ) . toBe ( expected ) ;
66
+ } ) ;
67
+
68
+ it ( 'should emit true if source element matches with predicate after subscription' , function ( ) {
69
+ var source = hot ( '--z--^--a--b--c--d--e--|' , { a : 5 , b : 10 , c : 15 , d : 20 , e : 25 } ) ;
70
+ var expected = '------------------(x|)' ;
71
+
72
+ expectObservable ( source . every ( predicate ) ) . toBe ( expected , { x : true } ) ;
73
+ } ) ;
74
+
75
+ it ( 'should emit false if source element does not match with predicate after subscription' , function ( ) {
76
+ var source = hot ( '--z--^--b--c--z--d--|' , { a : 5 , b : 10 , c : 15 , d : 20 } ) ;
77
+ var expected = '---------(x|)' ;
78
+
79
+ expectObservable ( source . every ( predicate ) ) . toBe ( expected , { x : false } ) ;
80
+ } ) ;
81
+
82
+ it ( 'should raise error if source raises error after subscription' , function ( ) {
83
+ var source = hot ( '--z--^--#' ) ;
84
+ var expected = '---#' ;
85
+
86
+ expectObservable ( source . every ( truePredicate ) ) . toBe ( expected ) ;
87
+ } ) ;
88
+
89
+ it ( 'should emit true if source does not emit after subscription' , function ( ) {
90
+ var source = hot ( '--z--^-----|' ) ;
91
+ var expected = '------(x|)' ;
92
+
93
+ expectObservable ( source . every ( predicate ) ) . toBe ( expected , { x : true } ) ;
94
+ } ) ;
95
+
96
+ } ) ;
0 commit comments