diff --git a/src/components/views/settings/UserProfileSettings.tsx b/src/components/views/settings/UserProfileSettings.tsx index f912fa44f53..1043833d8e9 100644 --- a/src/components/views/settings/UserProfileSettings.tsx +++ b/src/components/views/settings/UserProfileSettings.tsx @@ -131,6 +131,7 @@ const UserProfileSettings: React.FC = () => { setInitialDisplayName(displayName); } catch (e) { setDisplayNameError(true); + throw e; } }, [displayName, client]); diff --git a/test/components/views/settings/UserProfileSettings-test.tsx b/test/components/views/settings/UserProfileSettings-test.tsx index 75c714036ee..fd727729772 100644 --- a/test/components/views/settings/UserProfileSettings-test.tsx +++ b/test/components/views/settings/UserProfileSettings-test.tsx @@ -167,6 +167,25 @@ describe("ProfileSettings", () => { expect(client.setDisplayName).toHaveBeenCalledWith("The Value"); }); + it("displays error if changing display name fails", async () => { + jest.spyOn(OwnProfileStore.instance, "displayName", "get").mockReturnValue("Alice"); + mocked(client).setDisplayName.mockRejectedValue(new Error("Failed to set display name")); + + renderProfileSettings(toastRack, client); + + expect(editInPlaceOnSave).toBeDefined(); + + act(() => { + editInPlaceOnChange({ + target: { value: "Not Alice any more" } as HTMLInputElement, + } as ChangeEvent); + }); + + await act(async () => { + await expect(editInPlaceOnSave()).rejects.toEqual(expect.any(Error)); + }); + }); + it("resets on cancel", async () => { jest.spyOn(OwnProfileStore.instance, "displayName", "get").mockReturnValue("Alice");