UNPKG

@serenity-js/assertions

Version:

Serenity/JS universal assertion library supporting all types of functional tests, including both web and REST API scenarios

65 lines 2.31 kB
import { Expectation } from '@serenity-js/core'; /** * Creates an [expectation](https://serenity-js.org/api/core/class/Expectation/) that is met when the `actual` value is not undefined or null. * * Also, when the `actual` implements [`Optional`](https://serenity-js.org/api/core/interface/Optional/), * the expectation is met when calling [`Optional.isPresent`](https://serenity-js.org/api/core/interface/Optional/#isPresent) * returns an [`Answerable`](https://serenity-js.org/api/core/#Answerable) that resolves to `true` * * ## Ensuring that a value is defined * * ```ts * import { actorCalled } from '@serenity-js/core' * import { CallAnApi, Send, GetRequest, LastResponse } from '@serenity-js/rest' * import { Ensure, isPresent } from '@serenity-js/assertions' * * interface Product { * name: string; * } * * interface ProductsResponse { * products: Product[]; * } * * await actorCalled('Apisitt') * .whoCan(CallAnApi.at('https://api.example.org')) * .attemptsTo( * Send.a(GetRequest.to('/products')), * Ensure.that(LastResponse.body<ProductsResponse>().products[0], isPresent()), * ) * ``` * * ## Checking if a PageElement is present * * ```ts * import { actorCalled, Check } from '@serenity-js/core'; * import { BrowseTheWebWithPlaywright } from '@serenity-js/playwright'; * import { By, Click, Navigate, PageElement } from '@serenity-js/web'; * import { Browser, chromium } from 'playwright'; * * class NewsletterSubscription { * static modal = () => * PageElement.located(By.id('newsletter-subscription')) * .describedAs('newsletter subscription modal') * * static closeButton = () => * PageElement.located(By.class('.close')) * .of(NewsletterSubscription.modal()) * .describedAs('close button') * } * * const browser = await chromium.launch({ headless: true }); * * await actorCalled('Isabela') * .whoCan(BrowseTheWebWithPlaywright.using(browser)) * .attemptsTo( * Navigate.to(`https://example.org`), * Check.whether(NewsletterSubscription.modal(), isPresent()) * .andIfSo(Click.on(NewsletterSubscription.closeButton())), * ) * ``` * * @group Expectations */ export declare function isPresent<Actual>(): Expectation<Actual>; //# sourceMappingURL=isPresent.d.ts.map