unexpected
Advanced tools
Comparing version 1.0.13 to 1.1.0
@@ -566,3 +566,3 @@ // Copyright (c) 2013 Sune Simonsen <sune@we-knowhow.dk> | ||
expect.addAssertion('[not] to (throw|throw error|throw exception)', function (fn) { | ||
expect.addAssertion('[not] to (throw|throw error|throw exception)', function (arg) { | ||
if (typeof this.obj !== 'function') { | ||
@@ -575,2 +575,3 @@ throw new Error("Assertion '" + this.testDescription + | ||
var not = this.flags.not; | ||
var argType = typeof arg; | ||
@@ -581,15 +582,15 @@ try { | ||
var subject = 'string' === typeof e ? e : e.message; | ||
if ('function' === typeof fn) { | ||
fn(e); | ||
} else if ('object' === typeof fn) { | ||
if ('function' === argType) { | ||
arg(e); | ||
} else if ('string' === argType) { | ||
if (not) { | ||
expect(subject, 'not to match', fn); | ||
expect(subject, 'not to be', arg); | ||
} else { | ||
expect(subject, 'to match', fn); | ||
expect(subject, 'to be', arg); | ||
} | ||
} else if ('string' === typeof fn) { | ||
} else if (isRegExp(arg)) { | ||
if (not) { | ||
expect(subject, 'not to be', fn); | ||
expect(subject, 'not to match', arg); | ||
} else { | ||
expect(subject, 'to be', fn); | ||
expect(subject, 'to match', arg); | ||
} | ||
@@ -600,3 +601,3 @@ } | ||
if ('function' !== typeof fn && not) { | ||
if (('string' === argType || isRegExp(arg)) && not) { | ||
// in the presence of a matcher, ensure the `not` only applies to | ||
@@ -603,0 +604,0 @@ // the matching. |
{ | ||
"name": "unexpected", | ||
"version": "1.0.13", | ||
"version": "1.1.0", | ||
"author": "Sune Sloth Simonsen <sune@we-knowhow.dk>", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -249,3 +249,16 @@ /*global describe, it, expect*/ | ||
}, 'to throw', 'expected [Function] to throw exception'); | ||
}); | ||
it('fails if expection is throw', function () { | ||
expect(function () { | ||
expect(function () { | ||
throw new Error('The exception message'); | ||
}, 'not to throw exception'); | ||
}, 'to throw'); | ||
expect(function () { | ||
expect(function () { | ||
throw new Error('The exception message'); | ||
}, 'not to throw exception'); | ||
}, 'to throw', 'expected [Function] not to throw exception'); | ||
}); | ||
@@ -252,0 +265,0 @@ it('fails if the argument is not a function', function () { |
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
230988
6810