Code coverage report for lib/Assertion.js

Statements: 100% (37 / 37)      Branches: 100% (6 / 6)      Functions: 100% (5 / 5)      Lines: 100% (37 / 37)      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 561 1 1   1 4494 4494 4494 4494 4494 4494 4494 4494 4494 4494 4494     1 632 632   632       632 347 347 358 358 11         632     1 140 140 140 140     1 1099 1099 1099 140       1  
var shim = require('./shim');
var bind = shim.bind;
var forEach = shim.forEach;
 
function Assertion(expect, subject, testDescription, flags, alternations, args) {
    this.expect = expect;
    this.obj = subject; // deprecated
    this.equal = bind(expect.equal, expect); // deprecated
    this.eql = this.equal; // deprecated
    this.inspect = bind(expect.inspect, expect); // deprecated
    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();
 
    output.error('expected ')
        .append(expect.inspect(this.subject))
        .sp().error(this.testDescription);
 
    if (this.args.length > 0) {
        output.sp();
        forEach(this.args, function (arg, index) {
            output.append(expect.inspect(arg));
            if (index < this.args.length - 1) {
                output.text(', ');
            }
        }, this);
    }
 
    return output;
};
 
Assertion.prototype.throwStandardError = function () {
    var err = new Error();
    err.output = this.standardErrorMessage();
    err._isUnexpected = true;
    throw err;
};
 
Assertion.prototype.assert = function (condition) {
    var not = !!this.flags.not;
    condition = !!condition;
    if (condition === not) {
        this.throwStandardError();
    }
};
 
module.exports = Assertion;