diff --git a/public/app/core/components/AppChrome/TopBar/InviteUserButton.test.tsx b/public/app/core/components/AppChrome/TopBar/InviteUserButton.test.tsx
index 3b956d82187..9c90104ff68 100644
--- a/public/app/core/components/AppChrome/TopBar/InviteUserButton.test.tsx
+++ b/public/app/core/components/AppChrome/TopBar/InviteUserButton.test.tsx
@@ -262,5 +262,41 @@ describe('InviteUserButton', () => {
consoleSpy.mockRestore();
});
+
+ it('should handle URL generation errors gracefully', async () => {
+ mockGetExternalUserMngLinkUrl.mockImplementation(() => {
+ throw new Error('URL generation failed');
+ });
+
+ const consoleSpy = jest.spyOn(console, 'error').mockImplementation(() => {});
+ const user = userEvent.setup();
+
+ render();
+
+ // Should not crash when URL generation fails
+ await user.click(screen.getByRole('button', { name: /invite user/i }));
+
+ expect(consoleSpy).toHaveBeenCalledWith('Failed to handle button click:', expect.any(Error));
+
+ consoleSpy.mockRestore();
+ });
+
+ it('should handle popup blocking gracefully', async () => {
+ mockWindowOpen.mockImplementation(() => {
+ throw new Error('Popup blocked');
+ });
+
+ const consoleSpy = jest.spyOn(console, 'error').mockImplementation(() => {});
+ const user = userEvent.setup();
+
+ render();
+
+ // Should not crash when popup is blocked
+ await user.click(screen.getByRole('button', { name: /invite user/i }));
+
+ expect(consoleSpy).toHaveBeenCalledWith('Failed to handle button click:', expect.any(Error));
+
+ consoleSpy.mockRestore();
+ });
});
});