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

unexpected

Package Overview
Dependencies
Maintainers
3
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 10.28.0 to 10.29.0

logo.png

9

lib/createWrappedExpectProto.js

@@ -67,3 +67,3 @@ var createStandardErrorMessage = require('./createStandardErrorMessage');

output: unexpected.output,
outputFormat: unexpected.outputFormat,
outputFormat: unexpected.outputFormat.bind(unexpected),
format: unexpected.format,

@@ -74,3 +74,3 @@ withError: unexpected.withError,

var args = arguments;
var expect = this._context.expect;
var expect = this.context.expect;
this.callInNestedContext(function () {

@@ -97,3 +97,3 @@ expect.fail.apply(expect, args);

var that = this;
var expect = that._context.expect;
try {

@@ -118,5 +118,2 @@ var result = oathbreaker(callback());

wrappedError.originalError = e.originalError;
if (that._context.serializeErrorsFromWrappedExpect) {
expect.setErrorMessage(wrappedError);
}
throw wrappedError;

@@ -123,0 +120,0 @@ }

@@ -22,2 +22,13 @@ var createStandardErrorMessage = require('./createStandardErrorMessage');

function Context(unexpected) {
this.expect = unexpected;
this.level = 0;
}
Context.prototype.child = function () {
var child = Object.create(this);
child.level++;
return child;
};
var anyType = {

@@ -129,3 +140,3 @@ _unexpectedType: true,

function evaluateGroup(expect, subject, orGroup) {
function evaluateGroup(unexpected, context, subject, orGroup) {
return orGroup.map(function (expectation) {

@@ -145,3 +156,3 @@ var args = Array.prototype.slice.call(expectation);

} else {
return expect.apply(expect, args);
return unexpected._expect(context.child(), args);
}

@@ -153,3 +164,3 @@ })

function writeGroupEvaluationsToOutput(expect, output, groupEvaluations) {
function writeGroupEvaluationsToOutput(output, groupEvaluations) {
var hasOrClauses = groupEvaluations.length > 1;

@@ -215,10 +226,16 @@ var hasAndClauses = groupEvaluations.some(function (groupEvaluation) {

function createExpectIt(expect, expectations) {
function createExpectIt(unexpected, expectations) {
var orGroups = getOrGroups(expectations);
function expectIt(subject) {
function expectIt(subject, context) {
context = (
context &&
typeof context === 'object' &&
context instanceof Context
) ? context : new Context(unexpected);
var groupEvaluations = [];
var promises = [];
orGroups.forEach(function (orGroup) {
var evaluations = evaluateGroup(expect, subject, orGroup);
var evaluations = evaluateGroup(unexpected, context, subject, orGroup);
evaluations.forEach(function (evaluation) {

@@ -230,3 +247,3 @@ promises.push(evaluation.promise);

return oathbreaker(expect.promise.settle(promises).then(function () {
return oathbreaker(makePromise.settle(promises).then(function () {
groupEvaluations.forEach(function (groupEvaluation) {

@@ -245,4 +262,4 @@ groupEvaluation.forEach(function (evaluation) {

})) {
expect.fail(function (output) {
writeGroupEvaluationsToOutput(expect, output, groupEvaluations);
unexpected.fail(function (output) {
writeGroupEvaluationsToOutput(output, groupEvaluations);
});

@@ -258,3 +275,3 @@ }

copiedExpectations.push(arguments);
return createExpectIt(expect, copiedExpectations);
return createExpectIt(unexpected, copiedExpectations);
};

@@ -264,3 +281,3 @@ expectIt.or = function () {

copiedExpectations.push(OR, arguments);
return createExpectIt(expect, copiedExpectations);
return createExpectIt(unexpected, copiedExpectations);
};

@@ -271,3 +288,3 @@ return expectIt;

Unexpected.prototype.it = function () { // ...
return createExpectIt(this.expect, [arguments]);
return createExpectIt(this, [arguments]);
};

@@ -864,3 +881,3 @@

var expect = function () { /// ...
return unexpected._expect.apply(unexpected, arguments);
return unexpected._expect(new Context(unexpected), arguments);
};

@@ -1118,5 +1135,8 @@ expect.it = unexpected.it.bind(unexpected);

Unexpected.prototype._expect = function expect(subject, testDescriptionString) {
Unexpected.prototype._expect = function expect(context, args) {
var that = this;
if (arguments.length < 2) {
var subject = args[0];
var testDescriptionString = args[1];
if (args.length < 2) {
throw new Error('The expect function requires at least two parameters.');

@@ -1131,8 +1151,3 @@ } else if (testDescriptionString && testDescriptionString._expectIt) {

var executionContext = {
expect: that,
serializeErrorsFromWrappedExpect: false
};
function executeExpect(subject, testDescriptionString, args) {
function executeExpect(context, subject, testDescriptionString, args) {
var assertionRule = that.lookupAssertionRule(subject, testDescriptionString, args);

@@ -1182,3 +1197,3 @@

return wrappedExpect.callInNestedContext(function () {
return executeExpect(subject, testDescriptionString, args);
return executeExpect(context.child(), subject, testDescriptionString, args);
});

@@ -1189,3 +1204,3 @@ };

wrappedExpect._context = executionContext;
wrappedExpect.context = context;
wrappedExpect.execute = wrappedExpect;

@@ -1223,12 +1238,8 @@ wrappedExpect.alternations = assertionRule.alternations;

var args = new Array(arguments.length - 2);
for (var i = 2 ; i < arguments.length ; i += 1) {
args[i - 2] = arguments[i];
}
try {
var result = executeExpect(subject, testDescriptionString, args);
var result = executeExpect(context, subject, testDescriptionString, Array.prototype.slice.call(args, 2));
if (isPendingPromise(result)) {
that.expect.notifyPendingPromise(result);
result = result.then(undefined, function (e) {
if (e && e._isUnexpected) {
if (e && e._isUnexpected && context.level === 0) {
that.setErrorMessage(e);

@@ -1239,3 +1250,2 @@ }

} else {
executionContext.serializeErrorsFromWrappedExpect = true;
if (!result || typeof result.then !== 'function') {

@@ -1252,3 +1262,5 @@ result = makePromise.resolve(result);

}
that.setErrorMessage(newError);
if (context.level === 0) {
that.setErrorMessage(newError);
}
throw newError;

@@ -1255,0 +1267,0 @@ }

{
"name": "unexpected",
"version": "10.28.0",
"version": "10.29.0",
"author": "Sune Sloth Simonsen <sune@we-knowhow.dk>",

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

@@ -1,10 +0,4 @@

<h1 align=center>
<a href="http://unexpected.js.org/" title="Unexpected Documentation">
<img alt="Unexpected logo" width="200" src="http://unexpected.js.org/logo.png">
</a>
<br>
Unexpected
</h1>
# Unexpected
The extensible BDD assertion toolkit
Extensible BDD assertion toolkit

@@ -11,0 +5,0 @@ [![NPM version](https://badge.fury.io/js/unexpected.svg)](http://badge.fury.io/js/unexpected)

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

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