1
- import { formatters } from 'web3-core-helpers' ;
2
1
import SyncingSubscription from '../../../../src/subscriptions/eth/SyncingSubscription' ;
3
2
4
- // Mocks
5
- jest . mock ( 'web3-core-helpers' ) ;
6
-
7
3
/**
8
4
* SyncingSubscription test
9
5
*/
10
6
describe ( 'SyncingSubscriptionTest' , ( ) => {
11
7
let syncingSubscription ;
12
8
13
9
beforeEach ( ( ) => {
14
- syncingSubscription = new SyncingSubscription ( { } , formatters , { } ) ;
10
+ syncingSubscription = new SyncingSubscription ( { } , { } , { } ) ;
15
11
} ) ;
16
12
17
13
it ( 'constructor check' , ( ) => {
@@ -22,16 +18,10 @@ describe('SyncingSubscriptionTest', () => {
22
18
expect ( syncingSubscription . type ) . toEqual ( 'eth_subscribe' ) ;
23
19
24
20
expect ( syncingSubscription . options ) . toEqual ( null ) ;
25
-
26
- expect ( syncingSubscription . utils ) . toEqual ( { } ) ;
27
-
28
- expect ( syncingSubscription . formatters ) . toEqual ( formatters ) ;
29
-
30
- expect ( syncingSubscription . moduleInstance ) . toEqual ( { } ) ;
31
21
} ) ;
32
22
33
- it ( 'onNewSubscriptionItem calls outputSyncingFormatter and emits "changed" event (isSyncing: null) ' , ( done ) => {
34
- const item = { result : { syncing : true } } ;
23
+ it ( 'calls onNewSubscriptionItem and emits the initial "changed" event' , ( done ) => {
24
+ const item = { syncing : true } ;
35
25
36
26
syncingSubscription . on ( 'changed' , ( subscriptionItem ) => {
37
27
expect ( subscriptionItem ) . toEqual ( true ) ;
@@ -40,37 +30,28 @@ describe('SyncingSubscriptionTest', () => {
40
30
} ) ;
41
31
42
32
syncingSubscription . onNewSubscriptionItem ( item ) ;
43
-
44
- expect ( formatters . outputSyncingFormatter ) . toHaveBeenCalledWith ( item ) ;
45
33
} ) ;
46
34
47
- it ( 'onNewSubscriptionItem calls outputSyncingFormatter and emits "changed" event (isSyncing: true) ' , ( done ) => {
48
- const item = { result : { syncing : false } } ;
35
+ it ( 'calls onNewSubscriptionItem and emits the "changed" event' , ( done ) => {
36
+ const item = { syncing : false } ;
49
37
50
38
syncingSubscription . on ( 'changed' , ( subscriptionItem ) => {
51
- expect ( subscriptionItem ) . toEqual ( item . result . syncing ) ;
39
+ expect ( subscriptionItem ) . toEqual ( false ) ;
52
40
53
41
done ( ) ;
54
42
} ) ;
55
43
56
44
syncingSubscription . isSyncing = true ;
57
45
syncingSubscription . onNewSubscriptionItem ( item ) ;
58
-
59
- expect ( formatters . outputSyncingFormatter ) . toHaveBeenCalledWith ( item ) ;
60
46
} ) ;
61
47
62
- it ( 'onNewSubscriptionItem calls outputSyncingFormatter and emits "changed" event (isSyncing: false)' , ( done ) => {
63
- const item = { result : { syncing : true } } ;
64
-
65
- syncingSubscription . on ( 'changed' , ( subscriptionItem ) => {
66
- expect ( subscriptionItem ) . toEqual ( item . result . syncing ) ;
67
-
68
- done ( ) ;
69
- } ) ;
70
-
71
- syncingSubscription . isSyncing = false ;
72
- syncingSubscription . onNewSubscriptionItem ( item ) ;
48
+ it ( 'calls onNewSubscriptionItem and returns the boolean' , ( ) => {
49
+ expect ( syncingSubscription . onNewSubscriptionItem ( true ) ) . toEqual ( true ) ;
50
+ } ) ;
73
51
74
- expect ( formatters . outputSyncingFormatter ) . toHaveBeenCalledWith ( item ) ;
52
+ it ( 'calls onNewSubscriptionItem and returns the syncing status' , ( ) => {
53
+ expect (
54
+ syncingSubscription . onNewSubscriptionItem ( { status : true , syncing : true } )
55
+ ) . toEqual ( true ) ;
75
56
} ) ;
76
57
} ) ;
0 commit comments