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:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user