UNPKG

@serenity-js/core

Version:

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

32 lines 1.46 kB
import { ValueInspector } from '../../io/index.js'; import { Question } from '../Question.js'; import { Ability } from './Ability.js'; /** * 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 */ export class AnswerQuestions extends Ability { actor; constructor(actor) { super(); this.actor = actor; } answer(answerable) { if (AnswerQuestions.isDefined(answerable) && ValueInspector.isPromise(answerable)) { return answerable; } if (AnswerQuestions.isDefined(answerable) && Question.isAQuestion(answerable)) { return this.answer(answerable.answeredBy(this.actor)); } return Promise.resolve(answerable); } static isDefined(v) { return !(v === undefined || v === null); } } //# sourceMappingURL=AnswerQuestions.js.map