Skip to content

Commit

Permalink
fix: Replace deprecated addDomListener call (#689)
Browse files Browse the repository at this point in the history
* Replace deprecated addDomListener call

* Replace mock of addDomListener with addEventListener instead
  • Loading branch information
ellinge authored Apr 25, 2023
1 parent 9d120b7 commit 6a45bd2
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
5 changes: 3 additions & 2 deletions src/label.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,9 @@ export class Label extends OverlayViewSafe {
public addDomListener(
event: string,
handler: (event: Event) => void
): google.maps.MapsEventListener {
return google.maps.event.addDomListener(this.eventDiv, event, handler);
): google.maps.MapsEventListener {
this.eventDiv.addEventListener(event, handler);
return { remove: () => this.eventDiv.removeEventListener(event, handler) };
}

public onRemove(): void {
Expand Down
6 changes: 3 additions & 3 deletions src/marker.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ beforeEach(() => {

Label.prototype.setMap = jest.fn();

google.maps.event.addDomListener = jest.fn();
HTMLElement.prototype.addEventListener = jest.fn();
});

test("init should not pass extended options", () => {
Expand Down Expand Up @@ -82,7 +82,7 @@ test("should have interactive listeners", () => {
marker["addInteractiveListeners"]();

expect(
(google.maps.event.addDomListener as any).mock.calls.map((c: any[]) => c[1])
(HTMLElement.prototype.addEventListener as any).mock.calls.map((c: any[]) => c[0])
).toMatchInlineSnapshot(`
Array [
"mouseover",
Expand All @@ -105,7 +105,7 @@ test("should not have interactive listeners if no map", () => {
});
marker["addInteractiveListeners"]();

expect(google.maps.event.addDomListener as jest.Mock).toHaveBeenCalledTimes(
expect(HTMLElement.prototype.addEventListener as jest.Mock).toHaveBeenCalledTimes(
0
);
});
Expand Down

0 comments on commit 6a45bd2

Please sign in to comment.