"use strict";
var __extends = (this && this.__extends) || (function () {
    var extendStatics = Object.setPrototypeOf ||
        ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
        function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
    return function (d, b) {
        extendStatics(d, b);
        function __() { this.constructor = d; }
        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
    };
})();
Object.defineProperty(exports, "__esModule", { value: true });
var EventsTester = (function (_super) {
    __extends(EventsTester, _super);
    function EventsTester() {
        var _this = _super.call(this) || this;
        _this.count = 0;
        _this.handleTest = _this.handleTest.bind(_this);
        return _this;
    }
    EventsTester.prototype.bindTest = function () {
        this.on("test", this.handleTest);
    };
    EventsTester.prototype.unbindTest = function () {
        this.removeEventListener("test");
    };
    EventsTester.prototype.test = function () {
        this.emit("test");
    };
    EventsTester.prototype.reset = function () {
        this.count = 0;
        this.unbindTest();
    };
    EventsTester.prototype.handleTest = function () {
        this.count = this.count + 1;
    };
    return EventsTester;
}(Leaf.EventEmitter));
function run() {
    describe("Events", function () {
        var expect = chai.expect;
        var assert = chai.assert;
        var et = new EventsTester();
        describe("# on() & emit()", function () {
            it("cout should be 1 ", function () {
                et.bindTest();
                et.test();
                expect(et.count).to.equal(1);
                et.reset();
            });
        });
        describe("# removeEventListener()", function () {
            it("count should be 2", function () {
                function handleTest() {
                    et.handleTest();
                }
                et.bindTest();
                et.test();
                et.removeEventListener("test");
                et.test();
                et.on("test", handleTest);
                et.test();
                et.removeEventListener("test", handleTest);
                et.test();
                expect(et.count).to.equal(2);
                et.reset();
            });
        });
        describe("# addEventListener()", function () {
            it("count should be 1", function () {
                et.addEventListener("test", et.handleTest);
                et.test();
                expect(et.count).to.equal(1);
                et.reset();
            });
        });
        describe("# once()", function () {
            it("count should be 1", function () {
                et.once("test", et.handleTest);
                et.test();
                et.test();
                expect(et.count).to.equal(1);
                et.reset();
            });
        });
        describe("# listenBy()", function () {
            var obj = {};
            it("count should be 1", function () {
                et.listenBy(obj, "test", et.handleTest);
                et.test();
                expect(et.count).to.equal(1);
                et.reset();
            });
        });
        describe("# listenByOnce()", function () {
            var obj = {};
            it("count should be 1", function () {
                et.listenByOnce(obj, "test", et.handleTest);
                et.test();
                et.test();
                expect(et.count).to.equal(1);
                et.reset();
            });
        });
        describe("# stopListenBy()", function () {
            var obj = {};
            it("count should be 3", function () {
                function handleTest() {
                    et.handleTest();
                }
                et.listenBy(obj, "test", handleTest);
                et.test();
                et.stopListenBy(obj);
                et.test();
                et.listenBy(obj, "test", handleTest);
                et.test();
                et.stopListenBy(obj, "test");
                et.test();
                et.listenBy(obj, "test", handleTest);
                et.test();
                et.stopListenBy(obj, "test", handleTest);
                et.test();
                expect(et.count).to.equal(3);
                et.reset();
            });
        });
    });
}
exports.run = run;
//# sourceMappingURL=events.test.js.map