UNPKG

@serenity-js/core

Version:

The core Serenity/JS framework, providing the Screenplay Pattern interfaces, as well as the test reporting and integration infrastructure

53 lines 1.91 kB
import { ensure, isArray, isDefined, TinyType } from 'tiny-types'; import { inspected, ValueInspector } from '../../../io/index.js'; import { Name } from '../../../model/index.js'; import { Unanswered } from '../Unanswered.js'; /** * Used with [`ExpectationOutcome`](https://serenity-js.org/api/core/class/ExpectationOutcome/) to describe an [`Expectation`](https://serenity-js.org/api/core/class/Expectation/) and the arguments it's been executed with. * * @group Expectations */ export class ExpectationDetails extends TinyType { name; args; static of(functionName, ...functionArguments) { return new ExpectationDetails(new Name(functionName), functionArguments); } static fromJSON(o) { return new ExpectationDetails(Name.fromJSON(o.name), o.args.map(arg => { if (arg.type === Unanswered.name) { return new Unanswered(); } if (arg.type === ExpectationDetails.name) { return ExpectationDetails.fromJSON(arg.value); } // must be a JSONValue then return arg.value; })); } constructor(name, args) { super(); this.name = name; this.args = args; ensure('name', name, isDefined()); ensure('args', args, isArray()); } toString() { const argumentValues = this.args.map(arg => arg instanceof ExpectationDetails ? arg.toString() : inspected(arg, { compact: true })).join(', '); return `${this.name.value}(${argumentValues})`; } toJSON() { return { name: this.name.value, args: this.args.map(arg => ({ type: ValueInspector.typeOf(arg), value: arg['toJSON'] ? arg.toJSON() : arg, })), }; } } //# sourceMappingURL=ExpectationDetails.js.map