@@ -6,10 +6,18 @@ 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
+ // tslint:disable-next-line:no-unused-expression
17
+ new Hub ( testClient ) ;
18
+ expect ( spy ) . toHaveBeenCalledWith ( testClient ) ;
19
+ } ) ;
20
+
13
21
test ( 'push process into stack' , ( ) => {
14
22
const hub = new Hub ( ) ;
15
23
expect ( hub . getStack ( ) ) . toHaveLength ( 1 ) ;
@@ -51,15 +59,35 @@ describe('Hub', () => {
51
59
expect ( hub . getStack ( ) [ 1 ] . client ) . toBe ( testClient ) ;
52
60
} ) ;
53
61
54
- test ( 'bindClient' , ( ) => {
55
- const testClient : any = { bla : 'a' } ;
56
- const hub = new Hub ( testClient ) ;
57
- const ndClient : any = { foo : 'bar' } ;
58
- hub . pushScope ( ) ;
59
- hub . bindClient ( ndClient ) ;
60
- expect ( hub . getStack ( ) ) . toHaveLength ( 2 ) ;
61
- expect ( hub . getStack ( ) [ 0 ] . client ) . toBe ( testClient ) ;
62
- expect ( hub . getStack ( ) [ 1 ] . client ) . toBe ( ndClient ) ;
62
+ describe ( 'bindClient' , ( ) => {
63
+ test ( 'should override curent client' , ( ) => {
64
+ const testClient : any = { setupIntegrations : jest . fn ( ) } ;
65
+ const nextClient : any = { setupIntegrations : jest . fn ( ) } ;
66
+ const hub = new Hub ( testClient ) ;
67
+ hub . bindClient ( nextClient ) ;
68
+ expect ( hub . getStack ( ) ) . toHaveLength ( 1 ) ;
69
+ expect ( hub . getStack ( ) [ 0 ] . client ) . toBe ( nextClient ) ;
70
+ } ) ;
71
+
72
+ test ( 'should bind client to the top-most layer' , ( ) => {
73
+ const testClient : any = { bla : 'a' } ;
74
+ const nextClient : any = { foo : 'bar' } ;
75
+ const hub = new Hub ( testClient ) ;
76
+ hub . pushScope ( ) ;
77
+ hub . bindClient ( nextClient ) ;
78
+ expect ( hub . getStack ( ) ) . toHaveLength ( 2 ) ;
79
+ expect ( hub . getStack ( ) [ 0 ] . client ) . toBe ( testClient ) ;
80
+ expect ( hub . getStack ( ) [ 1 ] . client ) . toBe ( nextClient ) ;
81
+ } ) ;
82
+
83
+ test ( 'should call setupIntegration method of passed client' , ( ) => {
84
+ const testClient : any = { setupIntegrations : jest . fn ( ) } ;
85
+ const nextClient : any = { setupIntegrations : jest . fn ( ) } ;
86
+ const hub = new Hub ( testClient ) ;
87
+ hub . bindClient ( nextClient ) ;
88
+ expect ( testClient . setupIntegrations ) . toHaveBeenCalled ( ) ;
89
+ expect ( nextClient . setupIntegrations ) . toHaveBeenCalled ( ) ;
90
+ } ) ;
63
91
} ) ;
64
92
65
93
test ( 'inherit processors' , ( ) => {
0 commit comments