@@ -9,24 +9,87 @@ import { TestScheduler } from './scheduler/TestScheduler';
9
9
10
10
//workaround TS4029 by explicitly import types and avoid unused import error
11
11
( ( ) => Observable . toString ( ) ) ( ) ;
12
- ( ( ) => SubscriptionLog . toString ( ) ) ( ) ;
13
12
( ( ) => ColdObservable . toString ( ) ) ( ) ;
14
13
( ( ) => HotObservable . toString ( ) ) ( ) ;
15
14
16
- const rxSandbox = {
15
+ export type RxSandboxInstance = {
16
+ /**
17
+ * Creates a hot observable using marble diagram DSL, or TestMessage.
18
+ */
19
+ hot : typeof TestScheduler . prototype . createHotObservable ;
20
+ /**
21
+ * Creates a cold obsrevable using marbld diagram DSL, or TestMessage.
22
+ */
23
+ cold : typeof TestScheduler . prototype . createColdObservable ;
24
+ /**
25
+ * Flush out currently scheduled observables, fill values returned by `getMarbles`.
26
+ */
27
+ flush : typeof TestScheduler . prototype . flush ;
28
+ /**
29
+ * Get array of observable value's metadata TestMessage<T> from observable
30
+ * created via `hot` or `cold`. Returned array will be filled once scheduler flushes
31
+ * scheduled actions, either via explicit `flush` or implicit `autoFlush`.
32
+ */
33
+ getMessages : typeof TestScheduler . prototype . getMessages ;
34
+ /**
35
+ * Utility function to generate `expected` values via marble diagram.
36
+ */
37
+ e : < T = string > (
38
+ marble : string ,
39
+ value ?: { [ key : string ] : T } | null ,
40
+ error ?: any
41
+ ) => Readonly < Array < TestMessage < T | Array < TestMessage < T > > > > > ;
42
+ /**
43
+ * Utility function to generate `expected` subscriptions via marble diagram.
44
+ */
45
+ s : ( marble : string ) => SubscriptionLog ;
46
+ } ;
47
+
48
+ export interface RxSandbox {
49
+ /**
50
+ * Creates new instance of test scheduler for testing observables.
51
+ *
52
+ * @param {boolean } [autoFlush] Flush scheduler automatically when `getMarbles` is being called. False by default.
53
+ * @param {number } [frameTimeFactor] Custom frametime factor for virtual time frame. 1 by default.
54
+ *
55
+ * @return {RxSandboxInstance } instance of test scheduler interfaces.
56
+ */
57
+ create ( autoFlush ?: boolean , frameTimeFactor ?: number ) : RxSandboxInstance ;
58
+ /**
59
+ * Utility assertion method to assert marble based observable test messages.
60
+ * By default return values of sandbox functions are plain object works with
61
+ * any testing framework or assertion library, while this assertion provides
62
+ * better visualization against observable test messages.
63
+ *
64
+ */
65
+ marbleAssert ( ) : {
66
+ to : {
67
+ equal : ( ) => void ;
68
+ } ;
69
+ } ;
70
+ }
71
+
72
+ const rxSandbox : RxSandbox = {
17
73
create : ( autoFlush : boolean = false , frameTimeFactor : number = 1 ) => {
18
74
const scheduler = new TestScheduler ( autoFlush , frameTimeFactor ) ;
19
75
20
76
return {
21
77
hot : scheduler . createHotObservable . bind ( scheduler ) as typeof scheduler . createHotObservable ,
22
78
cold : scheduler . createColdObservable . bind ( scheduler ) as typeof scheduler . createColdObservable ,
23
79
flush : scheduler . flush . bind ( scheduler ) as typeof scheduler . flush ,
24
- getMarbles : scheduler . getMarbles . bind ( scheduler ) as typeof scheduler . getMarbles ,
80
+ getMessages : scheduler . getMessages . bind ( scheduler ) as typeof scheduler . getMessages ,
25
81
e : < T = string > ( marble : string , value ?: { [ key : string ] : T } | null , error ?: any ) =>
26
82
parseObservableMarble ( marble , value , error , true , frameTimeFactor ) ,
27
83
s : ( marble : string ) => parseSubscriptionMarble ( marble , frameTimeFactor )
28
84
} ;
29
- }
85
+ } ,
86
+ marbleAssert : ( ) => ( {
87
+ to : {
88
+ equal : ( ) => {
89
+ throw new Error ( 'not implemented' ) ;
90
+ }
91
+ }
92
+ } )
30
93
} ;
31
94
32
95
export { rxSandbox , TestMessage } ;
0 commit comments