diff --git a/plugins/user-settings/src/components/General/UserSettingsMenu.test.tsx b/plugins/user-settings/src/components/General/UserSettingsMenu.test.tsx index c8d30cd338..9c501bc775 100644 --- a/plugins/user-settings/src/components/General/UserSettingsMenu.test.tsx +++ b/plugins/user-settings/src/components/General/UserSettingsMenu.test.tsx @@ -14,8 +14,15 @@ * limitations under the License. */ -import { renderWithEffects, wrapInTestApp } from '@backstage/test-utils'; -import { fireEvent } from '@testing-library/react'; +import { + MockErrorApi, + renderInTestApp, + TestApiProvider, + renderWithEffects, + wrapInTestApp, +} from '@backstage/test-utils'; +import { errorApiRef, identityApiRef } from '@backstage/core-plugin-api'; +import { fireEvent, waitFor } from '@testing-library/react'; import React from 'react'; import { UserSettingsMenu } from './UserSettingsMenu'; @@ -30,4 +37,29 @@ describe('', () => { expect(rendered.getByText('Sign Out')).toBeInTheDocument(); }); + + it('handles errors that occur when signing out', async () => { + const failingIdentityApi = { + signOut: jest.fn().mockRejectedValue(new Error('Logout error')), + }; + const mockErrorApi = new MockErrorApi({ collect: true }); + const rendered = await renderInTestApp( + + + , + ); + + const menuButton = rendered.getByLabelText('more'); + fireEvent.click(menuButton); + fireEvent.click(rendered.getByText('Sign Out')); + + await waitFor(() => { + expect(mockErrorApi.getErrors()).toHaveLength(1); + }); + }); });