开玩笑和打字稿:构造函数super()上未涉及的分支

时间:2018-10-15 15:35:39

标签: typescript jestjs

我确切地知道,在构造函数上调用super()会导致branch not covered,因为打字稿是如何转换它的。 问题是,如何不会每次都显示此错误?

我有两节课:

class VastError extends Error {
    public readonly code: VastErrorCodes;

    constructor(code: VastErrorCodes) {
        super(`Error parsing vast: ${code}`);
        this.code = code;

        Object.setPrototypeOf(this, VastError.prototype);
    }
}

class LinearWrapper extends AbstractLinear {
    constructor(element: Element) {
        super(element);
    }
}

(我省略了实现细节)。 在第一种情况下,覆盖范围报告我致电super(Error parsing vast: ${code});时未覆盖的分支 对于第二类,不是。

请注意,obv打字稿会以相同的方式对它们进行转译:

function VastError(code) {
    var _this = _super.call(this, \"Error parsing vast: \" + code) || this;
    _this.code = code;
    Object.setPrototypeOf(_this, VastError.prototype);
    return _this;
}

function LinearWrapper(element) {
    var _this = _super.call(this, element) || this;
    return _this;
}

0 个答案:

没有答案
相关问题