Code coverage report for unexpected/lib/Assertion.js

Statements: 92.16% (47 / 51)      Branches: 100% (21 / 21)      Functions: 80% (4 / 5)      Lines: 92.16% (47 / 51)      Ignored: none     

All files » unexpected/lib/ » Assertion.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 831 3503 3503 3503 3503 3503 3503 3503     1 951 951   951   951   951 951 631 650 19 15   19   650 2   648         951 951 951 951   951   951 20   931     951   951 36   915     951   951 23 928 608     951   951     1 6 6     1             1  
function Assertion(expect, subject, testDescription, flags, alternations, args) {
    this.expect = expect;
    this.subject = subject;
    this.testDescription = testDescription;
    this.flags = flags;
    this.alternations = alternations;
    this.args = args;
    this.errorMode = 'default';
}
 
Assertion.prototype.standardErrorMessage = function () {
    var expect = this.expect;
    var output = expect.output.clone();
 
    var preamble = 'expected';
 
    var subjectOutput = expect.inspect(this.subject);
 
    var argsOutput = output.clone();
    if (this.args.length > 0) {
        this.args.forEach(function (arg, index) {
            if (0 < index) {
                if (index !== this.assertionIndex && index - 1 !== this.assertionIndex) {
                    argsOutput.text(',');
                }
                argsOutput.text(' ');
            }
            if (index === this.assertionIndex) {
                argsOutput.text(arg);
            } else {
                argsOutput.append(expect.inspect(arg));
            }
        }, this);
    }
 
    var subjectSize = subjectOutput.size();
    var argsSize = argsOutput.size();
    var width = preamble.length + subjectSize.width + argsSize.width + this.testDescription.length;
    var height = Math.max(subjectSize.height, argsSize.height);
 
    output.error(preamble);
 
    if (subjectSize.height > 1) {
        output.nl();
    } else {
        output.sp();
    }
 
    output.append(subjectOutput);
 
    if (subjectSize.height > 1 || (height === 1 && width > 120)) {
        output.nl();
    } else {
        output.sp();
    }
 
    output.error(this.testDescription);
 
    if (argsSize.height > 1) {
        output.nl();
    } else if (argsSize.width > 0) {
        output.sp();
    }
 
    output.append(argsOutput);
 
    return output;
};
 
Assertion.prototype.shift = function (expect, subject, assertionIndex) {
    this.assertionIndex = assertionIndex;
    expect.apply(expect, [subject].concat(this.args.slice(assertionIndex)));
};
 
Assertion.prototype.throwStandardError = function () {
    var err = new Error();
    err.output = this.standardErrorMessage();
    err._isUnexpected = true;
    throw err;
};
 
module.exports = Assertion;