UNPKG

unexpected

Version:
37 lines (31 loc) 1.52 kB
var createStandardErrorMessage = require('./createStandardErrorMessage'); 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 (options) { return createStandardErrorMessage(this.expect.output.clone(), this.expect, this.subject, this.testDescription, this.args, options); }; Assertion.prototype.shift = function (subject, assertionIndex) { if (arguments.length === 3) { // The 3-argument syntax for Assertion.prototype.shift is deprecated, please omit the first (expect) arg subject = arguments[1]; assertionIndex = arguments[2]; } var rest = this.args.slice(assertionIndex); this.args[assertionIndex] = this.expect.output.clone().error(this.args[assertionIndex]); var nextArgumentType = this.expect.findTypeOf(rest[0]); if (nextArgumentType.is('expect.it')) { return rest[0](subject); } else if (nextArgumentType.is('string')) { return this.expect.apply(this.expect, [subject].concat(rest)); } else { throw new Error('The "' + this.testDescription + '" assertion requires parameter #' + (assertionIndex + 2) + ' to be an expect.it function or a string specifying an assertion to delegate to'); } }; module.exports = Assertion;