import { Expectation, ExpectationMet, ExpectationNotMet, Outcome } from '@serenity-js/assertions'; import { AnswersQuestions } from '@serenity-js/core'; import { ElementFinder } from 'protractor'; import { promiseOf } from '../promiseOf'; /** * @access private */ export class ElementFinderExpectation extends Expectation { static forElementTo(message: string, fn: (actual: ElementFinder) => PromiseLike): Expectation { return new ElementFinderExpectation(message, fn); } constructor( private readonly message: string, private readonly fn: (actual: ElementFinder) => PromiseLike, ) { super(); } answeredBy(actor: AnswersQuestions): (actual: ElementFinder) => Promise> { return (actual: ElementFinder) => promiseOf(this.fn(actual)).then(_ => _ ? new ExpectationMet(this.toString(), null, actual) : new ExpectationNotMet(this.toString(), null, actual), ); } toString(): string { return this.message; } }