"use strict";
/**
 * Tests error chaining
 *
 *  Copyright (C) 2010-2019 R-T Specialty, LLC.
 *
 *  This file is part of the Liza Data Collection Framework.
 *
 *  liza is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU Affero General Public License as
 *  published by the Free Software Foundation, either version 3 of the
 *  License, or (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU Affero General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
Object.defineProperty(exports, "__esModule", { value: true });
var sut = require("../../src/error/ChainedError");
var chai_1 = require("chai");
describe('ChainedError', function () {
    it('can be created with generic error', function () {
        var eprev = new Error('previous error');
        chai_1.expect(sut.chain(new Error('new error'), eprev).chain).to.equal(eprev);
    });
    it('can be chained to arbitrary depth', function () {
        var e1 = new Error('lower');
        var e2 = sut.chain(new Error('mid'), e1);
        var e3 = sut.chain(new Error('outer'), e2);
        chai_1.expect(sut.isChained(e3)).to.be.true;
        chai_1.expect(sut.isChained(e2)).to.be.true;
        chai_1.expect(sut.isChained(e1)).to.be.false;
    });
    it('provides type predicate for TypeScript', function () {
        var inner = new Error('inner');
        // force to Error to discard ChainedError type
        var outer = sut.chain(new Error('outer'), inner);
        if (sut.isChained(outer)) {
            // if isChained was properly defined, then outer should now
            // have type ChainedError, and so this should compile
            chai_1.expect(outer.chain).to.equal(inner);
        }
        else {
            chai_1.expect.fail();
        }
    });
});
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiQ2hhaW5lZEVycm9yVGVzdC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIkNoYWluZWRFcnJvclRlc3QudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBOzs7Ozs7Ozs7Ozs7Ozs7Ozs7O0dB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