@@ -6,10 +6,17 @@ const clientFn: any = jest.fn();
6
6
7
7
describe ( 'Hub' , ( ) => {
8
8
afterEach ( ( ) => {
9
- jest . resetAllMocks ( ) ;
9
+ jest . restoreAllMocks ( ) ;
10
10
jest . useRealTimers ( ) ;
11
11
} ) ;
12
12
13
+ test ( 'call bindClient with provided client when constructing new instance' , ( ) => {
14
+ const testClient : any = { setupIntegrations : jest . fn ( ) } ;
15
+ const spy = jest . spyOn ( Hub . prototype , 'bindClient' ) ;
16
+ new Hub ( testClient ) ;
17
+ expect ( spy ) . toHaveBeenCalledWith ( testClient ) ;
18
+ } ) ;
19
+
13
20
test ( 'push process into stack' , ( ) => {
14
21
const hub = new Hub ( ) ;
15
22
expect ( hub . getStack ( ) ) . toHaveLength ( 1 ) ;
@@ -52,30 +59,33 @@ describe('Hub', () => {
52
59
} ) ;
53
60
54
61
describe ( 'bindClient' , ( ) => {
55
- test ( 'simple' , ( ) => {
62
+ test ( 'should override curent client' , ( ) => {
63
+ const testClient : any = { setupIntegrations : jest . fn ( ) } ;
64
+ const nextClient : any = { setupIntegrations : jest . fn ( ) } ;
65
+ const hub = new Hub ( testClient ) ;
66
+ hub . bindClient ( nextClient ) ;
67
+ expect ( hub . getStack ( ) ) . toHaveLength ( 1 ) ;
68
+ expect ( hub . getStack ( ) [ 0 ] . client ) . toBe ( nextClient ) ;
69
+ } ) ;
70
+
71
+ test ( 'should bind client to the top-most layer' , ( ) => {
56
72
const testClient : any = { bla : 'a' } ;
73
+ const nextClient : any = { foo : 'bar' } ;
57
74
const hub = new Hub ( testClient ) ;
58
- const ndClient : any = { foo : 'bar' } ;
59
75
hub . pushScope ( ) ;
60
- hub . bindClient ( ndClient ) ;
76
+ hub . bindClient ( nextClient ) ;
61
77
expect ( hub . getStack ( ) ) . toHaveLength ( 2 ) ;
62
78
expect ( hub . getStack ( ) [ 0 ] . client ) . toBe ( testClient ) ;
63
- expect ( hub . getStack ( ) [ 1 ] . client ) . toBe ( ndClient ) ;
64
- } ) ;
65
- test ( 'call setupIntegrations' , ( ) => {
66
- const setupIntegrations = jest . fn ( ) ;
67
- const testClient : any = { setupIntegrations } ;
68
- const hub = new Hub ( testClient ) ;
69
- hub . bindClient ( testClient ) ;
70
- expect ( setupIntegrations ) . toHaveBeenCalled ( ) ;
79
+ expect ( hub . getStack ( ) [ 1 ] . client ) . toBe ( nextClient ) ;
71
80
} ) ;
72
81
73
- test ( 'call setupIntegrations from constructor ' , ( ) => {
74
- const setupIntegrations = jest . fn ( ) ;
75
- const testClient : any = { setupIntegrations } ;
82
+ test ( 'should call setupIntegration method of passed client ' , ( ) => {
83
+ const testClient : any = { setupIntegrations : jest . fn ( ) } ;
84
+ const nextClient : any = { setupIntegrations : jest . fn ( ) } ;
76
85
const hub = new Hub ( testClient ) ;
77
- expect ( setupIntegrations ) . toHaveBeenCalled ( ) ;
78
- expect ( hub ) . toBeTruthy ( ) ;
86
+ hub . bindClient ( nextClient ) ;
87
+ expect ( testClient . setupIntegrations ) . toHaveBeenCalled ( ) ;
88
+ expect ( nextClient . setupIntegrations ) . toHaveBeenCalled ( ) ;
79
89
} ) ;
80
90
} ) ;
81
91
0 commit comments