{"size": 1109, "ext": "js", "max_stars_repo_path": "src/__test__/Dispatcher.test.js", "max_stars_repo_name": "jdbence/media-cast", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/__test__/Dispatcher.test.js", "max_issues_repo_name": "jdbence/media-cast", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/__test__/Dispatcher.test.js", "max_forks_repo_name": "jdbence/media-cast", "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": 23.1041666667, "max_line_length": 61, "alphanum_fraction": 0.5852119026}
/*global test expect jest*/
import Dispatcher from '../Dispatcher';

test('Add listener and catch event with passed data', () => {
  const f = jest.fn();
  const d = new Dispatcher();
  d.on('found', f);
  d.dispatch('found', 'waldo');
  expect(f).toBeCalledWith('waldo');
});

test('Dispatch only calls matching events', () => {
  const f = jest.fn();
  const d = new Dispatcher();
  d.on('found', f);
  d.dispatch('lost', 'waldo');
  expect(f).not.toHaveBeenCalled();
});

test('Only adds 1 listener per event:method', () => {
  const f = jest.fn();
  const d = new Dispatcher();
  d.on('found', f);
  d.on('found', f);
  d.on('found', f);
  d.on('found', f);
  expect(d.listeners.found.length).toEqual(1);
});

test('Remove listeners', () => {
  const f = jest.fn();
  const d = new Dispatcher();
  d.on('found', f);
  d.off('lost', f);
  d.off('found', f);
  expect(d.listeners.found).toEqual([]);
});

test('Destroys listeners', () => {
  const f = jest.fn();
  const d = new Dispatcher();
  d.on('search', f);
  d.on('found', f);
  d.on('list', f);
  d.destroy();
  expect(d.listeners).toEqual({});
});
