UNPKG

@serenity-js/core

Version:

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

36 lines 1.61 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.AnswerQuestions = void 0; const io_1 = require("../../io"); const Question_1 = require("../Question"); const Ability_1 = require("./Ability"); /** * This [`Ability`](https://serenity-js.org/api/core/class/Ability/) enables an [`Actor`](https://serenity-js.org/api/core/class/Actor/) to resolve the value of a given [`Answerable`](https://serenity-js.org/api/core/#Answerable). * * `AnswerQuestions` is used internally by [`Actor.answer`](https://serenity-js.org/api/core/class/Actor/#answer), and it is unlikely you'll ever need to use it directly in your code. * That is, unless you're building a custom Serenity/JS extension and want to override the default behaviour of the framework, * in which case you should check out the [Contributor's Guide](https://serenity-js.org/community/contributing/). * * @group Abilities */ class AnswerQuestions extends Ability_1.Ability { actor; constructor(actor) { super(); this.actor = actor; } answer(answerable) { if (AnswerQuestions.isDefined(answerable) && io_1.ValueInspector.isPromise(answerable)) { return answerable; } if (AnswerQuestions.isDefined(answerable) && Question_1.Question.isAQuestion(answerable)) { return this.answer(answerable.answeredBy(this.actor)); } return Promise.resolve(answerable); } static isDefined(v) { return !(v === undefined || v === null); } } exports.AnswerQuestions = AnswerQuestions; //# sourceMappingURL=AnswerQuestions.js.map