diff --git a/src/app.ts b/src/app.ts index 8ccd1ce..53ba082 100644 --- a/src/app.ts +++ b/src/app.ts @@ -256,8 +256,8 @@ export default class App { this.initComponentInCache() } - try { - this.getComponentView().then((componentView) => { + this.getComponentView() + .then((componentView) => { if (componentView && this.currentRoute) { if (!this.currentRoute.interfaceType) { this.currentRoute.interfaceType = @@ -273,9 +273,9 @@ export default class App { this.currentRoute.component.afterRender() } }) - } catch (error) { - console.warn('getComponentView::promise rejected') - } + .catch((error) => { + console.warn('getComponentView::promise rejected', error) + }) } } diff --git a/tests/unit/app.test.js b/tests/unit/app.test.js index e9e74ec..2056691 100644 --- a/tests/unit/app.test.js +++ b/tests/unit/app.test.js @@ -745,6 +745,33 @@ describe('App', () => { expect(app.currentRoute.component.afterRender).toHaveBeenCalled() }) + it('should call the createComponent function with a promise returning undefined (route has changed)', async () => { + app.currentRoute = { + component: { + afterRender: jest.fn() + }, + interfaceType: null, + isComponentClass: true, + isComponentClassReady: false + } + + app.initComponentInCache = jest.fn() + app.getComponentView = jest.fn().mockResolvedValue(undefined) + app.getInterfaceTypeFromView = jest.fn() + app.transformLinksInStringComponent = jest.fn() + app.target.appendChild = jest.fn() + console.warn = jest.fn() + + await app.createComponent() + + expect(app.initComponentInCache).toHaveBeenCalled() + expect(app.getComponentView).toHaveBeenCalled() + expect(app.getInterfaceTypeFromView).not.toHaveBeenCalled() + expect(app.transformLinksInStringComponent).not.toHaveBeenCalled() + expect(app.target.appendChild).not.toHaveBeenCalled() + expect(app.currentRoute.component.afterRender).not.toHaveBeenCalled() + }) + it('should call the createComponent function with a promise rejected', async () => { app.currentRoute = { component: { @@ -756,10 +783,12 @@ describe('App', () => { } app.initComponentInCache = jest.fn() - app.getComponentView = jest.fn() + app.getComponentView = jest.fn().mockRejectedValue(new Error('Promise rejection error')) + app.getInterfaceTypeFromView = jest.fn() app.transformLinksInStringComponent = jest.fn() app.target.appendChild = jest.fn() + app.test = jest.fn() console.warn = jest.fn() await app.createComponent() @@ -770,7 +799,6 @@ describe('App', () => { expect(app.transformLinksInStringComponent).not.toHaveBeenCalled() expect(app.target.appendChild).not.toHaveBeenCalled() expect(app.currentRoute.component.afterRender).not.toHaveBeenCalled() - expect(console.warn).toHaveBeenCalledWith('getComponentView::promise rejected') }) }) @@ -857,15 +885,11 @@ describe('App', () => { expect(result).toStrictEqual(