@@ -179,15 +179,33 @@ 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+ storeInstance . logger = {
193+ error : jest . fn ( ) ,
194+ log : jest . fn ( ) ,
195+ warn : jest . fn ( ) ,
196+ info : jest . fn ( ) ,
197+ trace : jest . fn ( ) ,
198+ } ;
189199
190200 await expect ( storeInstance . init ( initParams , jest . fn ( ) ) ) . rejects . toThrow ( 'registerCC failed' ) ;
201+
202+ expect ( storeInstance . logger . error ) . toHaveBeenCalledWith (
203+ 'CC-Widgets: Store init(): registration failed - Error: registerCC failed' ,
204+ {
205+ module : 'cc-store#store.ts' ,
206+ method : 'init' ,
207+ }
208+ ) ;
191209 } ) ;
192210
193211 it ( 'should reject the promise if Webex SDK fails to initialize' , async ( ) => {
@@ -206,5 +224,27 @@ describe('Store', () => {
206224
207225 await expect ( initPromise ) . rejects . toThrow ( 'Webex SDK failed to initialize' ) ;
208226 } ) ;
227+
228+ it ( 'should clear timeout and reject if Webex.init throws synchronously' , async ( ) => {
229+ const initParams = {
230+ webexConfig : { anyConfig : true } ,
231+ access_token : 'fake_token' ,
232+ } ;
233+
234+ const syncError = new Error ( 'sync init error' ) ;
235+ // @ts -expect-error overriding mock implementation for this test
236+ const initSpy = jest . spyOn ( Webex , 'init' ) . mockImplementation ( ( ) => {
237+ throw syncError ;
238+ } ) ;
239+
240+ await expect ( storeInstance . init ( initParams , jest . fn ( ) ) ) . rejects . toThrow ( 'sync init error' ) ;
241+
242+ expect ( initSpy ) . toHaveBeenCalledWith ( {
243+ config : initParams . webexConfig ,
244+ credentials : {
245+ access_token : initParams . access_token ,
246+ } ,
247+ } ) ;
248+ } ) ;
209249 } ) ;
210250} ) ;
0 commit comments