diff --git a/src/core/public/chrome/chrome_service.test.ts b/src/core/public/chrome/chrome_service.test.ts index eb73405118b6..be879bb4b5e9 100644 --- a/src/core/public/chrome/chrome_service.test.ts +++ b/src/core/public/chrome/chrome_service.test.ts @@ -109,6 +109,10 @@ afterAll(() => { }); describe('setup', () => { + afterEach(() => { + jest.restoreAllMocks(); + }); + it('register custom Nav Header render', async () => { const customHeaderMock = React.createElement('TestCustomNavHeader'); const renderMock = jest.fn().mockReturnValue(customHeaderMock); @@ -122,6 +126,24 @@ describe('setup', () => { expect(wrapper.prop('collapsibleNavHeaderRender')).toBeDefined(); expect(wrapper.prop('collapsibleNavHeaderRender')()).toEqual(customHeaderMock); }); + + it('should output warning message if calling `registerCollapsibleNavHeader` more than once', () => { + const warnMock = jest.fn(); + jest.spyOn(console, 'warn').mockImplementation(warnMock); + const customHeaderMock = React.createElement('TestCustomNavHeader'); + const renderMock = jest.fn().mockReturnValue(customHeaderMock); + const chrome = new ChromeService({ browserSupportsCsp: true }); + + const chromeSetup = chrome.setup(); + // call 1st time + chromeSetup.registerCollapsibleNavHeader(renderMock); + // call 2nd time + chromeSetup.registerCollapsibleNavHeader(renderMock); + expect(warnMock).toHaveBeenCalledTimes(1); + expect(warnMock).toHaveBeenCalledWith( + '[ChromeService] An existing custom collapsible navigation bar header render has been overridden.' + ); + }); }); describe('start', () => {