playwright-expect
Version:
The playwright-expect is an assertion library for TypeScript and JavaScript intended for use with a test runner such as Jest or Playwright Test.
43 lines (42 loc) • 1.27 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.toContainUrl = void 0;
const utils_1 = require("../utils/utils");
/**
* Use `toContainUrl` function when you want to check that page's url contains the expected url
*
* @example
* ```typescript
* await expect(page).toContainUrl('example');
*
* // also you can wait for the url
* await expect(page).toContainUrl('example', {timeout: 5000})
* ```
*
* @param this
* @param page
* @param expectedUrl
* @param options
* @returns
*/
async function toContainUrl(page, expectedUrl, options) {
try {
if (options === null || options === void 0 ? void 0 : options.timeout) {
await page.waitForURL(new RegExp(`${expectedUrl}`), { timeout: options.timeout });
}
const actualUrl = page.url();
return {
pass: actualUrl.includes(expectedUrl),
message: () => utils_1.getErrorMessage(this, 'toContainUrl', expectedUrl, actualUrl),
};
}
catch (error) {
return {
pass: false,
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
message: () => error.toString(),
};
}
}
exports.toContainUrl = toContainUrl;
;