<commit_before>
var fixture = '\
  <div class="parent">\
    <div class="event">\
      <div class="child">\
        <div class="grandchild"></div>\
      </div>\
    </div>\
    <input class="event-focus">\
  </div>\
';

describe ( 'Events', { beforeEach: getFixtureInit ( fixture ) }, function () {

  describe ( '$.fn.on', function ( it ) {

    it ( 'attaches a single event', function ( t ) {

      var ele = $('.event');
      var count = 0;
      var that;

      function handler () {
        count++;
        that = this;
      }

      ele.on ( 'click', handler );
      ele.trigger ( 'click' ).trigger ( 'click' );

      t.is ( count, 2 );
      t.is ( that, ele[0] );

    });

    it ( 'attaches multiple events', function ( t ) {

      var ele = $('.event');
      var count = 0;

      function handler () {
        count++;
      }

      ele.on ( 'foo bar', handler );
      ele.trigger ( 'foo' ).trigger ( 'bar' );

      t.is ( count, 2 );

    });

    it ( 'attaches multiple events via a map', function ( t ) {

      var ele = $('.event');
      var count = 0;

      function handler () {
        count++;
      }

      ele.on ({
        foo: handler,
        bar: handler
      });

      ele.trigger ( 'foo' ).trigger ( 'bar' );

      t.is ( count, 2 );

    });

    it ( 'stops propagation if false is returned', function ( t ) {

      var ele = $('.event');
      var parent = $('.parent');
      var count = 0;

      function handler () {
        count++;
        return false;
      }

      parent.on ( 'foo', handler );
      parent.on ( 'foo', handler );
      ele.on ( 'foo', handler );
      ele.on ( 'foo', handler ); // We are not using `stopImmediatePropagation`
      ele.trigger ( 'foo' );

      t.is ( count, 2 );

    });

    ( document.hasFocus () ? it : it.skip )( 'supports events that do not bubble', function ( t ) { // If the document isn't focused the element won't get the focus either

      var events = ['focus', 'blur', 'mouseenter', 'mouseleave'],
          eventsTrigger = ['focus', 'blur', 'mouseover', 'mouseout'];

      events.forEach ( function ( event, index ) {

        var ele = $('.event-focus');
        var parent = $('.parent');
        var count = 0;
        var eventTrigger = eventsTrigger[index];

        function handler () {
          count++;
        }

        parent.on ( event, handler );
        ele.on ( event, handler );
        ele.trigger ( eventTrigger );

        parent.off ( event );
        ele.off ( event );
        ele.trigger ( eventTrigger );

        t.is ( count, 2 );

      });

    });

    it ( 'calls native event triggerers directly', function ( t ) {

      var ele = $('.event-focus');
      var count = 0;

      ele[0].focus = function () {
        count++;
      };

      ele.trigger ( 'focus' );

      t.is ( count, 1 );

    });

    it ( 'supports namespaces', function ( t ) {
<commit_msg>focus|blur|mouseenter|mouseleave: updated tests to more closely reflect how jQuery behaves<commit_after>
var fixture = '\
  <div class="parent">\
    <div class="event">\
      <div class="child">\
        <div class="grandchild"></div>\
      </div>\
    </div>\
    <div class="event-focus" tabindex="-1">\
      <div class="event-focus-child" tabindex="-1"></div>\
    </div>\
  </div>\
';

describe ( 'Events', { beforeEach: getFixtureInit ( fixture ) }, function () {

  describe ( '$.fn.on', function ( it ) {

    it ( 'attaches a single event', function ( t ) {

      var ele = $('.event');
      var count = 0;
      var that;

      function handler () {
        count++;
        that = this;
      }

      ele.on ( 'click', handler );
      ele.trigger ( 'click' ).trigger ( 'click' );

      t.is ( count, 2 );
      t.is ( that, ele[0] );

    });

    it ( 'attaches multiple events', function ( t ) {

      var ele = $('.event');
      var count = 0;

      function handler () {
        count++;
      }

      ele.on ( 'foo bar', handler );
      ele.trigger ( 'foo' ).trigger ( 'bar' );

      t.is ( count, 2 );

    });

    it ( 'attaches multiple events via a map', function ( t ) {

      var ele = $('.event');
      var count = 0;

      function handler () {
        count++;
      }

      ele.on ({
        foo: handler,
        bar: handler
      });

      ele.trigger ( 'foo' ).trigger ( 'bar' );

      t.is ( count, 2 );

    });

    it ( 'stops propagation if false is returned', function ( t ) {

      var ele = $('.event');
      var parent = $('.parent');
      var count = 0;

      function handler () {
        count++;
        return false;
      }

      parent.on ( 'foo', handler );
      parent.on ( 'foo', handler );
      ele.on ( 'foo', handler );
      ele.on ( 'foo', handler ); // We are not using `stopImmediatePropagation`
      ele.trigger ( 'foo' );

      t.is ( count, 2 );

    });

    ( document.hasFocus () ? it.only : it.skip )( 'supports events that do not bubble', function ( t ) { // If the document isn't focused the element won't get the focus either

      var events = ['focus.namespace', 'focus', 'blur', 'focusin', 'focusout', 'mouseenter', 'mouseleave', 'mouseover', 'mouseout', 'focus', 'blur', 'mouseenter', 'mouseleave'],
          eventsTrigger = ['focus.namespace', 'focus', 'blur', 'focusin', 'focusout', 'mouseenter', 'mouseleave', 'mouseover', 'mouseout', 'focusin', 'focusout', 'mouseover', 'mouseout'],
          counts = [7, 7, 8, 14, 14, 14, 14, 14, 14, 4, 4, 14, 14];

      events.forEach ( function ( event, index ) {

        var doc = $(document);
        var ele = $('.event-focus');
        var parent = $('.parent');
        var child = $('event-focus-child');
        var count = 0;
        var eventTrigger = eventsTrigger[index];

        function handler () {
          count++;
        }

        doc.on ( event, handler );
        doc.on ( event, '.event-focus', handler );
        parent.on ( event, handler );
        parent.on ( event, '.event-focus', handler );
        ele.on ( event, handler );

        parent.trigger ( eventTrigger );
        parent.trigger ( eventTrigger );
        ele.trigger ( eventTrigger );
        ele.trigger ( eventTrigger );
        child.trigger ( eventTrigger );
        child.trigger ( eventTrigger );

        doc.off ( event, handler );
        doc.off ( event, '.event-focus', handler );
        parent.off ( event, handler );
        parent.off ( event, '.event-focus', handler );
        ele.off ( event, handler );

        parent.trigger ( eventTrigger );
        parent.trigger ( eventTrigger );
        ele.trigger ( eventTrigger );
        ele.trigger ( eventTrigger );
        child.trigger ( eventTrigger );
        child.trigger ( eventTrigger );

        t.is ( count, counts[index] );

      });

    });

    it ( 'calls native event triggerers directly', function ( t ) {

      var ele = $('.event-focus');
      var count = 0;

      ele[0].focus = function () {
        count++;
      };

      ele.trigger ( 'focus' );

      t.is ( count, 1 );

    });

    it ( 'supports namespaces', function ( t ) {

{'fraction_non_alphanumeric': 0.1681028393840938, 'fraction_numerical': 0.007063144511936714, 'mean_word_length': 1.879219194794632, 'pattern_counts': {'":': 0, '<': 24, '<?xml version=': 0, '>': 24, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7450327', 'n_tokens_mistral': 2207, 'n_tokens_neox': 2050, 'n_words': 610}