<commit_before>import { emit, prop, state, vdom } from '../../../src/index';
import component from '../../lib/component';

const { boolean, number } = prop;

describe('events (on*)', function () {
  it('should not duplicate listeners', function () {
    const myel = component({
      properties: {
        test: number({ default: 0 })
      },
      created (elem) {
        elem._test = 0;
      },
      render (elem) {
        vdom('div', {
          onevent () {
            elem._test++;
          }
        }, elem.test);
      }
    });

    const el = myel();
    const shadowDiv = el.shadowRoot.children[0];

    // Ensures that it rendered.
    expect(shadowDiv.textContent).to.equal('0');
    expect(el._test).to.equal(0);

    // Trigger the handler.
    emit(shadowDiv, 'event');

    // Ensure the event fired.
    expect(el._test).to.equal(1);

    // Re-render.
    state(el, { test: el.test + 1 });
    expect(shadowDiv.textContent).to.equal('1');
    emit(shadowDiv, 'event');
    expect(el._test).to.equal(2);

    state(el, { test: el.test + 1 });
    expect(shadowDiv.textContent).to.equal('2');
    emit(shadowDiv, 'event');
    expect(el._test).to.equal(3);
  });

  it('should not trigger events bubbled from descendants', function () {
    let called = false;
    const test = () => called = true;
    const myel = component({
      render () {
        vdom('div', { ontest: test }, vdom.bind(null, 'span'));
      }
    })();

    emit(myel.querySelector('span'), 'test');
    expect(called).to.equal(false);<commit_msg>Fix test that was incorrectly trying to query for a shadow node from the host node.<commit_after>import { emit, prop, state, vdom } from '../../../src/index';
import component from '../../lib/component';

const { boolean, number } = prop;

describe('events (on*)', function () {
  it('should not duplicate listeners', function () {
    const myel = component({
      properties: {
        test: number({ default: 0 })
      },
      created (elem) {
        elem._test = 0;
      },
      render (elem) {
        vdom('div', {
          onevent () {
            elem._test++;
          }
        }, elem.test);
      }
    });

    const el = myel();
    const shadowDiv = el.shadowRoot.children[0];

    // Ensures that it rendered.
    expect(shadowDiv.textContent).to.equal('0');
    expect(el._test).to.equal(0);

    // Trigger the handler.
    emit(shadowDiv, 'event');

    // Ensure the event fired.
    expect(el._test).to.equal(1);

    // Re-render.
    state(el, { test: el.test + 1 });
    expect(shadowDiv.textContent).to.equal('1');
    emit(shadowDiv, 'event');
    expect(el._test).to.equal(2);

    state(el, { test: el.test + 1 });
    expect(shadowDiv.textContent).to.equal('2');
    emit(shadowDiv, 'event');
    expect(el._test).to.equal(3);
  });

  it('should not trigger events bubbled from descendants', function () {
    let called = false;
    const test = () => called = true;
    const myel = component({
      render () {
        vdom('div', { ontest: test }, vdom.bind(null, 'span'));
      }
    })();
    emit(myel.shadowRoot.querySelector('span'), 'test');
    expect(called).to.equal(false);
{'fraction_non_alphanumeric': 0.18021424070573408, 'fraction_numerical': 0.007561436672967864, 'mean_word_length': 2.3957219251336896, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '5362483', 'n_tokens_mistral': 1013, 'n_tokens_neox': 984, 'n_words': 228}