unexpected
Advanced tools
Comparing version 3.2.1 to 3.2.2
@@ -253,3 +253,3 @@ /*global namespace*/ | ||
expect.addAssertion('[not] to (throw|throw error|throw exception)', function (expect, subject, arg) { | ||
this.errorMode = 'bubble'; | ||
this.errorMode = 'nested'; | ||
if (typeof subject !== 'function') { | ||
@@ -273,2 +273,4 @@ throw new Error("Assertion '" + this.testDescription + | ||
expect(subject, '[not] to match', arg); | ||
} else if (this.flags.not) { | ||
expect.fail('threw: {0}', e.message); | ||
} | ||
@@ -275,0 +277,0 @@ thrown = true; |
@@ -134,3 +134,5 @@ /*global namespace*/ | ||
var args = Array.prototype.slice.call(arguments, 1); | ||
throw new Error(this.format(message, args)); | ||
var error = new Error(this.format(message, args)); | ||
error._isUnexpected = true; | ||
throw error; | ||
}; | ||
@@ -317,13 +319,8 @@ | ||
var flags = extend({}, assertionRule.flags); | ||
var nestingLevel = 0; | ||
var wrappedExpect = function wrappedExpect(subject, testDescriptionString) { | ||
testDescriptionString = trim(testDescriptionString.replace(/\[(!?)([^\]]+)\] ?/g, function (match, negate, flag) { | ||
negate = !!negate; | ||
return flags[flag] !== negate ? flag + ' ' : ''; | ||
})); | ||
var args = Array.prototype.slice.call(arguments, 2); | ||
var callInNestedContext = function (callback) { | ||
nestingLevel += 1; | ||
try { | ||
that.expect.apply(that, [subject, testDescriptionString].concat(args)); | ||
callback(); | ||
nestingLevel -= 1; | ||
@@ -342,2 +339,14 @@ } catch (e) { | ||
var wrappedExpect = function wrappedExpect(subject, testDescriptionString) { | ||
testDescriptionString = trim(testDescriptionString.replace(/\[(!?)([^\]]+)\] ?/g, function (match, negate, flag) { | ||
negate = !!negate; | ||
return flags[flag] !== negate ? flag + ' ' : ''; | ||
})); | ||
var args = Array.prototype.slice.call(arguments, 2); | ||
callInNestedContext(function () { | ||
that.expect.apply(that, [subject, testDescriptionString].concat(args)); | ||
}); | ||
}; | ||
// Not sure this is the right way to go about this: | ||
@@ -348,2 +357,9 @@ wrappedExpect.equal = this.equal; | ||
wrappedExpect.inspect = this.inspect; | ||
wrappedExpect.fail = function () { | ||
var args = arguments; | ||
callInNestedContext(function () { | ||
that.fail.apply(that, args); | ||
}); | ||
}; | ||
wrappedExpect.format = this.format; | ||
@@ -350,0 +366,0 @@ var args = Array.prototype.slice.call(arguments, 2); |
{ | ||
"name": "unexpected", | ||
"version": "3.2.1", | ||
"version": "3.2.2", | ||
"author": "Sune Sloth Simonsen <sune@we-knowhow.dk>", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -367,3 +367,5 @@ (function () { | ||
var args = Array.prototype.slice.call(arguments, 1); | ||
throw new Error(this.format(message, args)); | ||
var error = new Error(this.format(message, args)); | ||
error._isUnexpected = true; | ||
throw error; | ||
}; | ||
@@ -550,13 +552,8 @@ | ||
var flags = extend({}, assertionRule.flags); | ||
var nestingLevel = 0; | ||
var wrappedExpect = function wrappedExpect(subject, testDescriptionString) { | ||
testDescriptionString = trim(testDescriptionString.replace(/\[(!?)([^\]]+)\] ?/g, function (match, negate, flag) { | ||
negate = !!negate; | ||
return flags[flag] !== negate ? flag + ' ' : ''; | ||
})); | ||
var args = Array.prototype.slice.call(arguments, 2); | ||
var callInNestedContext = function (callback) { | ||
nestingLevel += 1; | ||
try { | ||
that.expect.apply(that, [subject, testDescriptionString].concat(args)); | ||
callback(); | ||
nestingLevel -= 1; | ||
@@ -575,2 +572,14 @@ } catch (e) { | ||
var wrappedExpect = function wrappedExpect(subject, testDescriptionString) { | ||
testDescriptionString = trim(testDescriptionString.replace(/\[(!?)([^\]]+)\] ?/g, function (match, negate, flag) { | ||
negate = !!negate; | ||
return flags[flag] !== negate ? flag + ' ' : ''; | ||
})); | ||
var args = Array.prototype.slice.call(arguments, 2); | ||
callInNestedContext(function () { | ||
that.expect.apply(that, [subject, testDescriptionString].concat(args)); | ||
}); | ||
}; | ||
// Not sure this is the right way to go about this: | ||
@@ -581,2 +590,9 @@ wrappedExpect.equal = this.equal; | ||
wrappedExpect.inspect = this.inspect; | ||
wrappedExpect.fail = function () { | ||
var args = arguments; | ||
callInNestedContext(function () { | ||
that.fail.apply(that, args); | ||
}); | ||
}; | ||
wrappedExpect.format = this.format; | ||
@@ -1018,3 +1034,3 @@ var args = Array.prototype.slice.call(arguments, 2); | ||
expect.addAssertion('[not] to (throw|throw error|throw exception)', function (expect, subject, arg) { | ||
this.errorMode = 'bubble'; | ||
this.errorMode = 'nested'; | ||
if (typeof subject !== 'function') { | ||
@@ -1038,2 +1054,4 @@ throw new Error("Assertion '" + this.testDescription + | ||
expect(subject, '[not] to match', arg); | ||
} else if (this.flags.not) { | ||
expect.fail('threw: {0}', e.message); | ||
} | ||
@@ -1040,0 +1058,0 @@ thrown = true; |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
324144
6581