import reactify from '../../src/index';
import React from 'react';
import ReactDOM from 'react-dom';

describe('custom events', () => {
  it('should bind built-in events', done => {
    let count = 0;
    const Comp = reactify(document.registerElement('x-custom-event-1', {
      prototype: Object.create(HTMLElement.prototype, {
        trigger: {
          value() {
            this.dispatchEvent(new CustomEvent('click'));
          },
        },
      }),
    }), { React, ReactDOM });
    const comp = ReactDOM.render(<Comp onClick={() => count++} />, window.fixture);

    setTimeout(() => {
      ReactDOM.findDOMNode(comp).trigger();
      expect(count).to.equal(1);
      done();
    }, 1);
  });

  it('should bind custom events', done => {
    let count = 0;
    const Comp = reactify(document.registerElement('x-custom-event-2', {
      prototype: Object.create(HTMLElement.prototype, {
        trigger: {
          value() {
            this.dispatchEvent(new CustomEvent('test'));
          },
        },
      }),
    }), { React, ReactDOM });
    const comp = ReactDOM.render(<Comp ontest={() => count++} />, window.fixture);
    
    setTimeout(() => {
      ReactDOM.findDOMNode(comp).trigger();
      expect(count).to.equal(1);
      done();
    }, 1);
  });
});

@@ -1271,13 +1271,700 @@
 );%0A  %7D);
+%0A%0A  it('should not duplicate handlers', done =%3E %7B%0A    let count = 0;%0A    const Comp = reactify(document.registerElement('x-custom-event-3', %7B%0A      prototype: Object.create(HTMLElement.prototype, %7B%0A        trigger: %7B%0A          value() %7B%0A            this.dispatchEvent(new CustomEvent('test'));%0A          %7D,%0A        %7D,%0A      %7D),%0A    %7D), %7B React, ReactDOM %7D);%0A%0A    const func = () =%3E ++count;%0A%0A    // Using both ontest and onTest (case-sensitive) test case-sensitivity.%0A    const comp = ReactDOM.render(%3CComp ontest=%7Bfunc%7D onTest=%7Bfunc%7D /%3E, window.fixture);%0A%0A    setTimeout(() =%3E %7B%0A      ReactDOM.findDOMNode(comp).trigger();%0A      expect(count).to.equal(1);%0A      done();%0A    %7D, 1);%0A  %7D);
 %0A%7D);%0A

Add test to ensure event handlers aren't duplicated.