"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var events_matcher_1 = require("../drivers/events-matcher");
var eventemitter3_1 = require("eventemitter3");
var chai_1 = require("chai");
describe('events test driver', function () {
    var matcher;
    var emitter;
    beforeEach(function () {
        emitter = new eventemitter3_1.EventEmitter();
        matcher = new events_matcher_1.EventsMatcher({ retries: 5, interval: 10, noExtraEventsGrace: 20 });
    });
    it('failure when event has no type field', function () {
        matcher.track(emitter, 'event');
        return chai_1.expect(function () { return emitter.emit('event', { foo: 'bar' }); }).to.throw(Error);
    });
    it('failure when event has incorrect type field', function () {
        matcher.track(emitter, 'event');
        return chai_1.expect(function () { return emitter.emit('event', { type: 'eventz', foo: 'bar' }); }).to.throw(Error);
    });
    it('success when existing events', function () {
        matcher.track(emitter, 'event');
        emitter.emit('event', { type: 'event', foo: 'bar' });
        return matcher.expect([{ type: 'event', foo: 'bar' }]);
    });
    it('success when subset events', function () {
        matcher.track(emitter, 'event');
        emitter.emit('event', { type: 'event', foo: 'bar' });
        return matcher.expect([{ type: 'event' }]);
    });
    it('error contains original chai data', function () {
        matcher.track(emitter, 'event');
        emitter.emit('event', { type: 'event', foo: 'bar' });
        var rejection = matcher.expect([{ type: 'event', foo: 'baz' }]).catch(function (e) { return e; });
        return chai_1.expect(rejection).to.eventually.satisfy(function (err) { return chai_1.expect(err).to.containSubset({ actual: [{ foo: 'bar' }], expected: [{ foo: 'baz' }] }); });
    });
    it('failure when mismatched events', function () {
        matcher.track(emitter, 'event');
        emitter.emit('event', { type: 'event', foo: 'bar' });
        return chai_1.expect(matcher.expect([{ type: 'event', foo: 'baz' }])).to.be.rejectedWith(/{ type: 'event', foo: 'bar' }/);
    });
    it('success when matching delayed events', function () {
        matcher.track(emitter, 'event');
        var result = matcher.expect([{ type: 'event', foo: 'bar' }]);
        setTimeout(function () { return emitter.emit('event', { type: 'event', foo: 'bar' }); }, 25);
        return result;
    });
});
//# sourceMappingURL=events-matcher.spec.js.map