{"size": 1031, "ext": "js", "max_stars_repo_path": "spec/handlers_spec.js", "max_stars_repo_name": "vhl/action-combinator", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "spec/handlers_spec.js", "max_issues_repo_name": "vhl/action-combinator", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "spec/handlers_spec.js", "max_forks_repo_name": "vhl/action-combinator", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 20.62, "max_line_length": 76, "alphanum_fraction": 0.5528612997}
import {
  addHandler,
  removeHandler,
} from 'handlers';

import {
  actionToPromise as run,
} from 'core';

import $ from 'jquery';

describe('handlers', function() {
  /** @type {jest.Mock} */
  let myHandler;

  beforeEach(function() {
    myHandler = jest.fn();
    document.body.innerHTML = '<div class="foo"></div>';
  });

  describe('#addHandler', function() {
    it(
      `
      adds a given handler for a given event to an element matching a given
      selector
      `,
      function() {
        run(addHandler('.foo', 'bar', myHandler));
        $('.foo').trigger('bar');
        expect(myHandler).toHaveBeenCalled();
      },
    );
  });

  describe('#removeHandler', function() {
    it(
      `
      removes the handler for a given event from an element matching a given
      selector
      `,
      function() {
        $('.foo').on('bar', myHandler);
        run(removeHandler('.foo', 'bar'));
        $('.foo').trigger('bar');
        expect(myHandler).not.toHaveBeenCalled();
      },
    );
  });
});
