@@ -179,15 +179,34 @@ describe('Store', () => {
179179 expect ( storeInstance . registerCC ) . toHaveBeenCalledWith ( mockWebex ) ;
180180 } ) ;
181181
182- it ( 'should reject the promise if registerCC fails in init method' , async ( ) => {
182+ it ( 'should log an error and reject the promise if registerCC fails in init method' , async ( ) => {
183183 const initParams = {
184184 webexConfig : { anyConfig : true } ,
185185 access_token : 'fake_token' ,
186186 } ;
187187
188- jest . spyOn ( storeInstance , 'registerCC' ) . mockRejectedValue ( new Error ( 'registerCC failed' ) ) ;
188+ const error = new Error ( 'registerCC failed' ) ;
189+ jest . spyOn ( storeInstance , 'registerCC' ) . mockRejectedValue ( error ) ;
190+
191+ // Provide a logger so the init() error handler can log without failing
192+ // @ts -expect-error partial logger mock for test
193+ storeInstance . logger = {
194+ error : jest . fn ( ) ,
195+ log : jest . fn ( ) ,
196+ warn : jest . fn ( ) ,
197+ info : jest . fn ( ) ,
198+ trace : jest . fn ( ) ,
199+ } ;
189200
190201 await expect ( storeInstance . init ( initParams , jest . fn ( ) ) ) . rejects . toThrow ( 'registerCC failed' ) ;
202+
203+ expect ( storeInstance . logger . error ) . toHaveBeenCalledWith (
204+ 'CC-Widgets: Store init(): registration failed - Error: registerCC failed' ,
205+ {
206+ module : 'cc-store#store.ts' ,
207+ method : 'init' ,
208+ }
209+ ) ;
191210 } ) ;
192211
193212 it ( 'should reject the promise if Webex SDK fails to initialize' , async ( ) => {
@@ -206,5 +225,27 @@ describe('Store', () => {
206225
207226 await expect ( initPromise ) . rejects . toThrow ( 'Webex SDK failed to initialize' ) ;
208227 } ) ;
228+
229+ it ( 'should clear timeout and reject if Webex.init throws synchronously' , async ( ) => {
230+ const initParams = {
231+ webexConfig : { anyConfig : true } ,
232+ access_token : 'fake_token' ,
233+ } ;
234+
235+ const syncError = new Error ( 'sync init error' ) ;
236+ // @ts -expect-error overriding mock implementation for this test
237+ const initSpy = jest . spyOn ( Webex , 'init' ) . mockImplementation ( ( ) => {
238+ throw syncError ;
239+ } ) ;
240+
241+ await expect ( storeInstance . init ( initParams , jest . fn ( ) ) ) . rejects . toThrow ( 'sync init error' ) ;
242+
243+ expect ( initSpy ) . toHaveBeenCalledWith ( {
244+ config : initParams . webexConfig ,
245+ credentials : {
246+ access_token : initParams . access_token ,
247+ } ,
248+ } ) ;
249+ } ) ;
209250 } ) ;
210251} ) ;
0 commit comments