@@ -6,10 +6,18 @@ const clientFn: any = jest.fn();
66
77describe ( 'Hub' , ( ) => {
88 afterEach ( ( ) => {
9- jest . resetAllMocks ( ) ;
9+ jest . restoreAllMocks ( ) ;
1010 jest . useRealTimers ( ) ;
1111 } ) ;
1212
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+
1321 test ( 'push process into stack' , ( ) => {
1422 const hub = new Hub ( ) ;
1523 expect ( hub . getStack ( ) ) . toHaveLength ( 1 ) ;
@@ -51,15 +59,35 @@ describe('Hub', () => {
5159 expect ( hub . getStack ( ) [ 1 ] . client ) . toBe ( testClient ) ;
5260 } ) ;
5361
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+ } ) ;
6391 } ) ;
6492
6593 test ( 'inherit processors' , ( ) => {
0 commit comments