UNPKG

playwright-fluent

Version:
37 lines (36 loc) 1.43 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.expectThatDialogIsOfType = void 0; const utils_1 = require("../../utils"); const fluent_api_1 = require("../../fluent-api"); async function expectThatDialogIsOfType(dialog, dialogType, options = fluent_api_1.defaultAssertOptions) { const waitOptions = { ...utils_1.defaultWaitUntilOptions, ...fluent_api_1.defaultAssertOptions, ...options, throwOnTimeout: true, }; switch (dialogType) { case 'alert': case 'beforeunload': case 'confirm': case 'prompt': break; default: throw new Error(`Unknown dialog type: '${dialogType}'. It should be 'alert', 'confirm', 'prompt' or 'beforeunload'`); } await (0, utils_1.waitUntil)(async () => { const currentDialog = dialog(); if (!currentDialog) { return false; } return currentDialog && currentDialog.type() === dialogType; }, async () => { const currentDialog = dialog(); if (!currentDialog) { return `No dialog has been opened. Maybe you forgot to call the '.withDialogs()' on the playwright-fluent instance.`; } return `Current dialog is of type '${currentDialog.type()}' but it should be '${dialogType}'`; }, waitOptions); } exports.expectThatDialogIsOfType = expectThatDialogIsOfType;