resolve undefined this in onClick handler (#32576)

* resolve undefined this in onClick handler

* add regression test for bound DisambiguatedProfileViewModel onClick

* Update docs

* add regression for sender profile click mention insertion

* Eslint Fix
This commit is contained in:
Zack
2026-02-19 13:55:52 +00:00
committed by GitHub
parent d597fc61d6
commit 134c7cde46
4 changed files with 59 additions and 3 deletions
@@ -75,13 +75,27 @@ describe("DisambiguatedProfileViewModel", () => {
const subscriber = jest.fn();
vm.subscribe(subscriber);
onClick({} as never);
vm.onClick?.({} as never);
expect(onClick).toHaveBeenCalledTimes(1);
expect(subscriber).not.toHaveBeenCalled();
expect(vm.getSnapshot()).toBe(prevSnapshot);
});
it("should keep onClick bound when extracted as a callback", () => {
const onClick = jest.fn();
const vm = new DisambiguatedProfileViewModel({
member,
fallbackName: "Fallback",
onClick,
});
const clickHandler = vm.onClick;
expect(() => clickHandler?.({} as never)).not.toThrow();
expect(onClick).toHaveBeenCalledTimes(1);
});
it("should emit snapshot update when fallbackName changes", () => {
const vm = new DisambiguatedProfileViewModel({
member: null,