{"size": 1524, "ext": "js", "max_stars_repo_path": "__tests__/probaclick.test.js", "max_stars_repo_name": "alexmacarthur/hover-watch", "max_stars_repo_stars_event_min_datetime": "2018-10-14T04:19:46.000Z", "max_stars_repo_stars_event_max_datetime": "2021-11-16T13:56:29.000Z", "max_issues_repo_path": "__tests__/probaclick.test.js", "max_issues_repo_name": "alexmacarthur/hover-watch", "max_issues_repo_issues_event_min_datetime": "2020-05-31T02:42:31.000Z", "max_issues_repo_issues_event_max_datetime": "2021-07-17T19:26:45.000Z", "max_forks_repo_path": "__tests__/probaclick.test.js", "max_forks_repo_name": "alexmacarthur/hover-watch", "max_forks_repo_forks_event_min_datetime": "2020-04-17T05:49:22.000Z", "max_forks_repo_forks_event_max_datetime": "2021-07-16T13:13:49.000Z"}
{"max_stars_count": 72, "max_issues_count": 13, "max_forks_count": 4, "avg_line_length": 31.1020408163, "max_line_length": 71, "alphanum_fraction": 0.6916010499}
import ProbaClick from "../src/probaclick";

describe("event listeners", () => {
  test("removes event listeners when remove() is called", () => {
    document.body.innerHTML = `
    <button class="button">Button #1</button>
    <button class="button">Button #2</button>
  `;

    const buttons = document.querySelectorAll("button");
    const addEventListenerMock = jest.fn();
    const removeEventListenerMock = jest.fn();

    buttons.forEach((button) => {
      button.addEventListener = addEventListenerMock;
      button.removeEventListener = removeEventListenerMock;
    });

    const instance = ProbaClick(buttons);
    instance.remove();

    // Called two times for each button.
    expect(addEventListenerMock).toHaveBeenCalledTimes(4);
    expect(removeEventListenerMock).toHaveBeenCalledTimes(4);
  });

  test("does not remove listeners when remove() is not called", () => {
    document.body.innerHTML = `
    <button class="button">Button #1</button>
    <button class="button">Button #2</button>
  `;

    const buttons = document.querySelectorAll("button");
    const addEventListenerMock = jest.fn();
    const removeEventListenerMock = jest.fn();

    buttons.forEach((button) => {
      button.addEventListener = addEventListenerMock;
      button.removeEventListener = removeEventListenerMock;
    });

    ProbaClick(buttons);

    // Called two times for each button.
    expect(addEventListenerMock).toHaveBeenCalledTimes(4);
    expect(removeEventListenerMock).toHaveBeenCalledTimes(0);
  });
});
