1- import { Observable , Subject } from '@reactivex/rxjs '
2- import '../xs/rx '
1+ import { streamOps } from '../xs '
2+ import '../xs/array '
33import { FantasyX } from '../fantasy/fantasyx'
4+ import { Id } from '../fantasy/typeclasses/id'
45import { Update } from '../interfaces'
56import { Xstream } from '../fantasy/xstream'
67import { flatMap , FlatMap } from '../fantasy/typeclasses/flatmap'
78import { concat , Semigroup } from '../fantasy/typeclasses/semigroup'
89describe ( 'FantasyX' , ( ) => {
910 let intent ;
1011 beforeEach ( ( ) => {
11- intent = new Subject ( )
12+ intent = streamOps . subject ( )
1213 } )
13- it ( 'map and fold' , ( done ) => {
14- Xstream
14+ it ( 'map and fold' , ( ) => {
15+ intent . next ( 1 )
16+ intent . next ( 2 )
17+ let res = Xstream
1518 . fromIntent ( )
1619 . toFantasyX ( )
1720 . map ( a => {
@@ -23,59 +26,44 @@ describe('FantasyX', () => {
2326 } )
2427 . foldS ( ( s , a ) => ( { count : a . count + s . count } ) )
2528 . toStream ( intent )
26- . reduce ( ( acc , f : any ) => {
27- return f ( acc )
28- } , { count : 10 } )
29- . subscribe ( a => {
30- expect ( a . count ) . toBe ( 22 ) // 5 + 10 + 7
31- done ( )
32- } ) ;
29+ . reduce ( ( acc , f ) => f ( acc ) , { count : 10 } )
30+ expect ( res ) . toEqual ( { count : 10 + 5 + 7 } )
31+ } )
32+
33+ it ( 'flatMap Xstream' , ( ) => {
3334 intent . next ( 1 )
3435 intent . next ( 2 )
35- intent . complete ( )
36- } )
3736
38- it ( 'flatMap Xstream' , ( done ) => {
39- FlatMap . Xstream . flatMap (
40- ( x : number ) => Xstream . fromPromise < "RxStream" , number , number > ( Promise . resolve ( { count : x + 1 } ) )
41- , Xstream . fromIntent < "RxStream" , number > ( ) )
37+ let res = FlatMap . Xstream . flatMap (
38+ ( x : number ) => Xstream . fromPromise < "ArrayStream" , number , number > ( new Id ( { count : x + 1 } ) )
39+ , Xstream . fromIntent < "ArrayStream" , number > ( ) )
4240 . toFantasyX ( )
4341 . toStream ( intent )
4442 . reduce ( ( acc , f : any ) => f ( acc ) , { count : 10 } )
45- . toPromise ( ) . then ( a => expect ( a ) . toEqual ( { count : 3 } ) ) . then ( done )
46- intent . next ( 1 )
47- intent . next ( 2 )
48- intent . complete ( )
43+ expect ( res ) . toEqual ( { count : 3 } )
4944 } )
5045
51- it ( 'concat object' , ( done ) => {
52- Semigroup . Xstream . concat (
46+ it ( 'concat object' , ( ) => {
47+ intent . next ( { count1 : 1 } )
48+ intent . next ( { count2 : 2 } )
49+
50+ let res = Semigroup . Xstream . concat (
5351 Xstream . fromIntent ( )
5452 , Xstream . fromIntent ( ) )
5553 . toFantasyX ( )
5654 . toStream ( intent )
5755 . reduce ( ( acc , f : any ) => f ( acc ) , { count : 0 } )
58- . toPromise ( )
59- . then ( a => expect ( a ) . toEqual (
60- { "count" : 0 , "count1" : 1 , "count2" : 2 }
61- ) )
62- . then ( done )
63- intent . next ( { count1 : 1 } )
64- intent . next ( { count2 : 2 } )
65- intent . complete ( )
56+ expect ( res ) . toEqual ( { "count" : 0 , "count1" : 1 , "count2" : 2 } )
6657 } )
6758
68- it ( 'concat promise' , ( done ) => {
69- Semigroup . Xstream . concat (
70- Xstream . fromPromise ( Promise . resolve ( { count1 : 1 } ) )
71- , Xstream . fromPromise ( Promise . resolve ( { count2 : 2 } ) ) )
59+ it ( 'concat promise' , ( ) => {
60+
61+ let res = Semigroup . Xstream . concat (
62+ Xstream . fromPromise ( new Id ( { count1 : 1 } ) )
63+ , Xstream . fromPromise ( new Id ( { count2 : 2 } ) ) )
7264 . toFantasyX ( )
7365 . toStream ( intent )
7466 . reduce ( ( acc , f : any ) => f ( acc ) , { count : 0 } )
75- . toPromise ( )
76- . then ( a => expect ( a ) . toEqual (
77- { "count" : 0 , "count1" : 1 , "count2" : 2 }
78- ) )
79- . then ( done )
67+ expect ( res ) . toEqual ( { "count" : 0 , "count1" : 1 , "count2" : 2 } )
8068 } )
8169} )
0 commit comments