<commit_before><commit_msg>add tests for AppDispatcher<commit_after>jest.autoMockOff();

describe('AppDispatcher', function() {
  var AppDispatcher;

  beforeEach(function() {
    AppDispatcher = require('../AppDispatcher').default;
  });

  it('sends actions to subscribers', function() {
    var listener = jest.genMockFunction();
    AppDispatcher.register(listener);

    var payload = {};
    AppDispatcher.dispatch(payload);
    expect(listener.mock.calls.length).toBe(1);
    expect(listener.mock.calls[0][0]).toBe(payload);
  });

  it('waits with chained dependencies properly', function() {
    var payload = {};

    var listener1Done = false;
    var listener1 = function(pl) {
      AppDispatcher.waitFor([index2, index4]);
      
      expect(listener2Done).toBe(true);
      expect(listener3Done).toBe(true);
      expect(listener4Done).toBe(true);
      listener1Done = true;
    };
    var index1 = AppDispatcher.register(listener1);

    var listener2Done = false;
    var listener2 = function(pl) {
      AppDispatcher.waitFor([index3]);
      expect(listener3Done).toBe(true);
      listener2Done = true;
    };
    var index2 = AppDispatcher.register(listener2);

    var listener3Done = false;
    var listener3 = function(pl) {
      listener3Done = true;
    };
    var index3 = AppDispatcher.register(listener3);

    var listener4Done = false;
    var listener4 = function(pl) {
      AppDispatcher.waitFor([index3]);
      expect(listener3Done).toBe(true);
      listener4Done = true;
    };
    var index4 = AppDispatcher.register(listener4);
  });
});
{'fraction_non_alphanumeric': 0.13227848101265824, 'fraction_numerical': 0.020253164556962026, 'mean_word_length': 3.530085959885387, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5002831', 'n_tokens_mistral': 481, 'n_tokens_neox': 456, 'n_words': 86}