Code coverage report for lib/Assertion.js

Statements: 92.73% (51 / 55)      Branches: 100% (23 / 23)      Functions: 80% (4 / 5)      Lines: 92.73% (51 / 55)      Ignored: none     

All files » 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 83 84 85 86 871 5309 5309 5309 5309 5309 5309 5309     1 1201 1201   1201   1201   1201 1201 741 741 771 771 30 24   30   771 60   711   771       1201 1201 1201 1201   1201   1201 38   1163     1201   1201 58   1143     1201   1201 36 1165 705     1201   1201     1 7 7 7     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) {
        var previousArgWasMagicPen = false;
        this.args.forEach(function (arg, index) {
            var isMagicPen = arg && arg.isMagicPen;
            if (0 < index) {
                if (!isMagicPen && !previousArgWasMagicPen) {
                    argsOutput.text(',');
                }
                argsOutput.text(' ');
            }
            if (isMagicPen) {
                argsOutput.append(arg);
            } else {
                argsOutput.append(expect.inspect(arg));
            }
            previousArgWasMagicPen = isMagicPen;
        }, 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) {
    var rest = this.args.slice(assertionIndex);
    this.args[assertionIndex] = expect.output.clone().error(this.args[assertionIndex]);
    expect.apply(expect, [subject].concat(rest));
};
 
Assertion.prototype.throwStandardError = function () {
    var err = new Error();
    err.output = this.standardErrorMessage();
    err._isUnexpected = true;
    throw err;
};
 
module.exports = Assertion;