Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

unexpected

Package Overview
Dependencies
Maintainers
1
Versions
330
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

unexpected - npm Package Compare versions

Comparing version 0.1.0 to 0.1.1

46

lib/unexpected.js

@@ -57,2 +57,19 @@ // Copyright (c) 2013 Sune Simonsen <sune@we-knowhow.dk>

var assertions = {};
function truncateStack(err, fn) {
if (Error.captureStackTrace) {
Error.captureStackTrace(err, fn);
} else if ('stack' in err) {
// Excludes IE<10, and fn cannot be anonymous for this backup plan to work:
var stackEntries = err.stack.split(/\r\n?|\n\r?/),
needle = 'at ' + fn.name + ' ';
for (var i = 0 ; i < stackEntries.length ; i += 1) {
if (stackEntries[i].indexOf(needle) !== -1) {
stackEntries.splice(1, i);
err.stack = stackEntries.join("\n");
}
}
}
}
function expect(subject, testDescriptionString) {

@@ -68,3 +85,8 @@ var assertionRule = assertions[testDescriptionString];

var handler = assertionRule.handler;
handler.apply(assertion, args);
try {
handler.apply(assertion, args);
} catch (e) {
truncateStack(e, expect);
throw e;
}
} else {

@@ -75,3 +97,5 @@ var similarAssertions = expect.findAssertionSimilarTo(testDescriptionString);

'did you mean: "' + similarAssertions[0] + '"';
throw new Error(message);
var err = new Error(message);
truncateStack(err, expect);
throw err;
}

@@ -257,5 +281,5 @@ }

'array' === type ? isArray(subject) :
'object' === type ?
'object' === typeof subject && null !== subject :
type === typeof subject);
'object' === type ? 'object' === typeof subject && null !== subject :
/^reg(?:exp?|ular expression)$/.test(type) ? isRegExp(subject) :
type === typeof subject);
} else {

@@ -269,4 +293,4 @@ this.assert(subject instanceof type);

// Alias for common 'to [not] be (a|an)' assertions
expect.addAssertion('to [not] be (a|an) (boolean|number|string|function|object|array)', function () {
var matches = /(.*) (\w+)/.exec(this.testDescription);
expect.addAssertion('to [not] be (a|an) (boolean|number|string|function|object|array|regexp|regex|regular expression)', function () {
var matches = /(.* be (?:a|an)) ([\w\s]+)/.exec(this.testDescription);
expect(this.obj, matches[1], matches[2]);

@@ -887,2 +911,8 @@ });

// Converting to array solves the problem.
if (isRegExp(a)) {
if (!isRegExp(b)) {
return false;
}
return a.source === b.source && a.global === b.global && a.ignoreCase === b.ignoreCase && a.multiline === b.multiline;
}
if (isArguments(a)) {

@@ -1232,4 +1262,4 @@ if (!isArguments(b)) {

})();
//////////////////////////////////////////////////////////////////////////
// Support three module loading scenarios

@@ -1236,0 +1266,0 @@ if (typeof require === 'function' && typeof exports === 'object' && typeof module === 'object') {

2

package.json
{
"name": "unexpected",
"version": "0.1.0",
"version": "0.1.1",
"author": "Sune Sloth Simonsen <sune@we-knowhow.dk>",

@@ -5,0 +5,0 @@ "keywords": [

@@ -35,2 +35,12 @@ /*global describe, it, expect*/

});
it('throws with a stack trace that has the calling function as the top frame when the assertion fails (if the environment supports it)', function () {
if (Error.captureStackTrace || 'stack' in new Error()) {
expect(function TheCallingFunction() {
expect(4 < 4, 'to be ok');
}, 'to throw exception', function (err) {
expect(err.stack.split('\n')[1], 'to match', /TheCallingFunction/);
});
}
});
});

@@ -70,2 +80,8 @@

expect([], 'to be an', Array);
expect(/ab/, 'to be a', RegExp);
expect(/ab/, 'to be a regexp');
expect(123, 'to not be a regex');
expect(/ab/, 'to be a regex');
expect(/ab/, 'to be a regular expression');
expect(123, 'to not be a regular expression');
expect(null, 'to not be an', 'object');

@@ -107,2 +123,7 @@ expect(null, 'to not be an object');

expect({ a: { b: 'c' } }, 'to not equal', { a: { b: 'd' } });
expect(/foo/, 'to equal', /foo/);
expect(/foo/i, 'to not equal', /foo/);
expect(/foo/gm, 'to equal', /foo/gm);
expect(/foo/m, 'to not equal', /foo/i);
expect(/foo/m, 'to equal', new RegExp('foo', 'm'));
});

@@ -109,0 +130,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc