Socket
Socket
Sign inDemoInstall

@serenity-js/assertions

Package Overview
Dependencies
Maintainers
1
Versions
360
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@serenity-js/assertions - npm Package Compare versions

Comparing version 2.0.1-alpha.49 to 2.0.1-alpha.50

11

CHANGELOG.md

@@ -6,2 +6,13 @@ # Change Log

## [2.0.1-alpha.50](https://github.com/jan-molak/serenity-js/compare/v2.0.1-alpha.49...v2.0.1-alpha.50) (2019-04-18)
### Features
* **assertions:** Ensure can embed the assertion error in any custom RuntimeError ([e18d331](https://github.com/jan-molak/serenity-js/commit/e18d331))
## [2.0.1-alpha.49](https://github.com/jan-molak/serenity-js/compare/v2.0.1-alpha.48...v2.0.1-alpha.49) (2019-04-17)

@@ -8,0 +19,0 @@

12

lib/Ensure.d.ts

@@ -1,10 +0,14 @@

import { Answerable, AnswersQuestions, Interaction } from '@serenity-js/core';
import { Answerable, AnswersQuestions, AssertionError, Interaction, RuntimeError } from '@serenity-js/core';
import { Expectation } from './Expectation';
import { Outcome } from './outcomes';
export declare class Ensure<Actual> extends Interaction {
private readonly actual;
private readonly expectation;
static that<A>(actual: Answerable<A>, expectation: Expectation<any, A>): Ensure<any>;
protected readonly actual: Answerable<Actual>;
protected readonly expectation: Expectation<Actual>;
static that<A>(actual: Answerable<A>, expectation: Expectation<any, A>): Ensure<A>;
constructor(actual: Answerable<Actual>, expectation: Expectation<Actual>);
performAs(actor: AnswersQuestions): PromiseLike<void>;
toString(): string;
otherwiseFailWith(typeOfRuntimeError: new (message: string, cause?: Error) => RuntimeError, message?: string): Interaction;
protected errorForOutcome(outcome: Outcome<any, Actual>): RuntimeError;
protected asAssertionError(outcome: Outcome<any, Actual>): AssertionError;
}

@@ -46,7 +46,7 @@ "use strict";

.when(outcomes_1.ExpectationNotMet, function (o) {
throw new core_1.AssertionError("Expected " + io_1.formatted(templateObject_1 || (templateObject_1 = __makeTemplateObject(["", ""], ["", ""])), _this.actual) + " to " + o.message, o.expected, o.actual);
throw _this.errorForOutcome(o);
})
.when(outcomes_1.ExpectationMet, function (_) { return void 0; })
.else(function (o) {
throw new core_1.LogicError(io_1.formatted(templateObject_2 || (templateObject_2 = __makeTemplateObject(["An Expectation should return an instance of an Outcome, not ", ""], ["An Expectation should return an instance of an Outcome, not ", ""])), o));
throw new core_1.LogicError(io_1.formatted(templateObject_1 || (templateObject_1 = __makeTemplateObject(["An Expectation should return an instance of an Outcome, not ", ""], ["An Expectation should return an instance of an Outcome, not ", ""])), o));
});

@@ -57,8 +57,31 @@ });

Ensure.prototype.toString = function () {
return io_1.formatted(templateObject_3 || (templateObject_3 = __makeTemplateObject(["#actor ensures that ", " does ", ""], ["#actor ensures that ", " does ", ""])), this.actual, this.expectation);
return io_1.formatted(templateObject_2 || (templateObject_2 = __makeTemplateObject(["#actor ensures that ", " does ", ""], ["#actor ensures that ", " does ", ""])), this.actual, this.expectation);
};
Ensure.prototype.otherwiseFailWith = function (typeOfRuntimeError, message) {
return new EnsureOrFailWithCustomError(this.actual, this.expectation, typeOfRuntimeError, message);
};
Ensure.prototype.errorForOutcome = function (outcome) {
return this.asAssertionError(outcome);
};
Ensure.prototype.asAssertionError = function (outcome) {
return new core_1.AssertionError("Expected " + io_1.formatted(templateObject_3 || (templateObject_3 = __makeTemplateObject(["", ""], ["", ""])), this.actual) + " to " + outcome.message, outcome.expected, outcome.actual);
};
return Ensure;
}(core_1.Interaction));
exports.Ensure = Ensure;
var EnsureOrFailWithCustomError = /** @class */ (function (_super) {
__extends(EnsureOrFailWithCustomError, _super);
function EnsureOrFailWithCustomError(actual, expectation, typeOfRuntimeError, message) {
var _this = _super.call(this, actual, expectation) || this;
_this.typeOfRuntimeError = typeOfRuntimeError;
_this.message = message;
return _this;
}
EnsureOrFailWithCustomError.prototype.errorForOutcome = function (outcome) {
var assertionError = this.asAssertionError(outcome);
return new this.typeOfRuntimeError(this.message || assertionError.message, assertionError);
};
return EnsureOrFailWithCustomError;
}(Ensure));
var templateObject_1, templateObject_2, templateObject_3;
//# sourceMappingURL=Ensure.js.map
{
"name": "@serenity-js/assertions",
"version": "2.0.1-alpha.49",
"version": "2.0.1-alpha.50",
"description": "Screenplay-style assertion library",

@@ -49,4 +49,4 @@ "author": {

"@documentation/esdoc-template": "2.0.1-alpha.41",
"@integration/testing-tools": "2.0.1-alpha.49",
"@serenity-js/core": "2.0.1-alpha.49",
"@integration/testing-tools": "2.0.1-alpha.50",
"@serenity-js/core": "2.0.1-alpha.50",
"tiny-types": "1.12.1"

@@ -77,3 +77,3 @@ },

},
"gitHead": "3684ec8405d7229dd78e148e220dfde241f04f40"
"gitHead": "fa687ded8d3b46af105838b8b91b36e806a71b77"
}

@@ -1,2 +0,2 @@

import { Answerable, AnswersQuestions, AssertionError, Interaction, LogicError } from '@serenity-js/core';
import { Answerable, AnswersQuestions, AssertionError, Interaction, LogicError, RuntimeError } from '@serenity-js/core';
import { formatted } from '@serenity-js/core/lib/io';

@@ -9,3 +9,3 @@ import { match } from 'tiny-types';

export class Ensure<Actual> extends Interaction {
static that<A>(actual: Answerable<A>, expectation: Expectation<any, A>) {
static that<A>(actual: Answerable<A>, expectation: Expectation<any, A>): Ensure<A> {
return new Ensure(actual, expectation);

@@ -15,4 +15,4 @@ }

constructor(
private readonly actual: Answerable<Actual>,
private readonly expectation: Expectation<Actual>,
protected readonly actual: Answerable<Actual>,
protected readonly expectation: Expectation<Actual>,
) {

@@ -31,7 +31,3 @@ super();

.when(ExpectationNotMet, o => {
throw new AssertionError(
`Expected ${ formatted`${this.actual}` } to ${ o.message }`,
o.expected,
o.actual,
);
throw this.errorForOutcome(o);
})

@@ -49,2 +45,35 @@ .when(ExpectationMet, _ => void 0)

}
otherwiseFailWith(typeOfRuntimeError: new (message: string, cause?: Error) => RuntimeError, message?: string): Interaction {
return new EnsureOrFailWithCustomError(this.actual, this.expectation, typeOfRuntimeError, message);
}
protected errorForOutcome(outcome: Outcome<any, Actual>): RuntimeError {
return this.asAssertionError(outcome);
}
protected asAssertionError(outcome: Outcome<any, Actual>) {
return new AssertionError(
`Expected ${ formatted`${ this.actual }` } to ${ outcome.message }`,
outcome.expected,
outcome.actual,
);
}
}
class EnsureOrFailWithCustomError<Actual> extends Ensure<Actual> {
constructor(
actual: Answerable<Actual>,
expectation: Expectation<Actual>,
private readonly typeOfRuntimeError: new (message: string, cause?: Error) => RuntimeError,
private readonly message?: string,
) {
super(actual, expectation);
}
protected errorForOutcome(outcome: Outcome<any, Actual>): RuntimeError {
const assertionError = this.asAssertionError(outcome);
return new this.typeOfRuntimeError(this.message || assertionError.message, assertionError);
}
}

Sorry, the diff of this file is not supported yet

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