<commit_before>import 'skatejs-named-slots';
import { emit } from '../src/index';
import { number } from '../src/properties';
import * as IncrementalDOM from 'incremental-dom';
import kickflip from '../src/kickflip';
import state from '../src/state';
import vdom, { IncrementalDOM as VdomIncrementalDOM } from '../src/vdom';
import version from '../src/version';

let componentCount = 0;

function component (opts) {
  return kickflip(`my-el-${++componentCount}`, opts);
}

function element (opts) {
  return component(opts)();
}

describe('kickflip', function () {
  it('kickflip', function () {
    expect(kickflip).to.be.a('function');
  });

  it('state', function () {
    expect(state).to.be.a('function');
  });

  it('vdom', function () {
    expect(vdom).to.be.a('function');
  });

  it('version', function () {
    expect(version).to.be.a('string');
  });
});

describe('events (on*)', function () {
  it('should not duplicate listeners', function (done) {
    const myel = component({
      properties: {
        test: number({ default: 0 })
      },
      created (elem) {<commit_msg>Write test for built-in and custom event binding.<commit_after>import 'skatejs-named-slots';
import { emit } from '../src/index';
import { number } from '../src/properties';
import * as IncrementalDOM from 'incremental-dom';
import kickflip from '../src/kickflip';
import state from '../src/state';
import vdom, { IncrementalDOM as VdomIncrementalDOM } from '../src/vdom';
import version from '../src/version';

let componentCount = 0;

function component (opts) {
  return kickflip(`my-el-${++componentCount}`, opts);
}

function element (opts) {
  return component(opts)();
}

describe('kickflip', function () {
  it('kickflip', function () {
    expect(kickflip).to.be.a('function');
  });

  it('state', function () {
    expect(state).to.be.a('function');
  });

  it('vdom', function () {
    expect(vdom).to.be.a('function');
  });

  it('version', function () {
    expect(version).to.be.a('string');
  });
});

describe('events (on*)', function () {
  it('built-in events', function () {
    let count = 0;
    const el = element({
      render () {
        vdom('div', { onclick: () => ++count });
      }
    }).shadowRoot.firstChild;
    expect(count).to.equal(0);
    expect(el.onclick).to.be.a('function');
    el.onclick();
    expect(count).to.equal(1);
    emit(el, 'click');
    expect(count).to.equal(2);
  });

  it('custom events', function () {
    let count = 0;
    const el = element({
      render () {
        vdom('div', { ontest: () => ++count });
      }
    }).shadowRoot.firstChild;
    expect(count).to.equal(0);
    expect(el.test).to.equal(undefined)
    emit(el, 'test');
    expect(count).to.equal(1);
  });

  it('should not duplicate listeners', function (done) {
    const myel = component({
      properties: {
        test: number({ default: 0 })
      },
      created (elem) {
{'fraction_non_alphanumeric': 0.19746314706890641, 'fraction_numerical': 0.0037709976002742542, 'mean_word_length': 3.322962962962963, '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': '1490064', 'n_tokens_mistral': 973, 'n_tokens_neox': 924, 'n_words': 209}