Skip to content

Commit

Permalink
Release 11.1.2
Browse files Browse the repository at this point in the history
  • Loading branch information
btd committed Dec 10, 2016
1 parent 813a5f9 commit 644a407
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 6 deletions.
5 changes: 5 additions & 0 deletions History.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
11.1.2 / 2016-12-10
===================

* Added workaround for runtimes where error's stack populated eagerly

11.1.1 / 2016-10-10
===================

Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"name": "should",
"description": "test framework agnostic BDD-style assertions",
"version": "11.1.1",
"author": "TJ Holowaychuk <[email protected]>, Denis Bardadym <[email protected]> and other contributors",
"version": "11.1.2",
"author": "TJ Holowaychuk <[email protected]>, Denis Bardadym <[email protected]>",
"repository": {
"type": "git",
"url": "https://github.com/shouldjs/should.js.git"
Expand Down
37 changes: 33 additions & 4 deletions should.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*!
* should - test framework agnostic BDD-style assertions
* @version v11.1.1
* @author TJ Holowaychuk <[email protected]>, Denis Bardadym <[email protected]> and other contributors
* @version v11.1.2
* @author TJ Holowaychuk <[email protected]>, Denis Bardadym <[email protected]>
* @link https://github.com/shouldjs/should.js
* @license MIT
*/
Expand Down Expand Up @@ -1500,6 +1500,28 @@
}
});

// a bit hacky way how to get error to do not have stack
function LightAssertionError(options) {
merge(this, options);

if (!options.message) {
Object.defineProperty(this, 'message', {
get: function() {
if (!this._message) {
this._message = this.generateMessage();
this.generatedMessage = true;
}
return this._message;
}
});
}
}

LightAssertionError.prototype = {
generateMessage: AssertionError.prototype.generateMessage
};


/**
* should Assertion
* @param {*} obj Given object for assertion
Expand Down Expand Up @@ -1562,7 +1584,11 @@

params.assertion = this;

throw new AssertionError(params);
if (this.light) {
throw new LightAssertionError(params);
} else {
throw new AssertionError(params);
}
},

/**
Expand Down Expand Up @@ -1635,12 +1661,13 @@
value: function() {
var context = new Assertion(this.obj, this, name);
context.anyOne = this.anyOne;
context.light = true;

try {
func.apply(context, arguments);
} catch (e) {
// check for fail
if (e instanceof AssertionError) {
if (e instanceof AssertionError || e instanceof LightAssertionError) {
// negative fail
if (this.negate) {
this.obj = context.obj;
Expand All @@ -1654,6 +1681,7 @@

// positive fail
context.negate = false;
context.light = false;
context.fail();
}
// throw if it is another exception
Expand All @@ -1664,6 +1692,7 @@
if (this.negate) {
context.negate = true; // because .fail will set negate
context.params.details = 'false negative fail';
context.light = false;
context.fail();
}

Expand Down

0 comments on commit 644a407

Please sign in to comment.