Skip to content

Commit

Permalink
feat(expect) - add ignoreCase option for toHaveURL (#30192)
Browse files Browse the repository at this point in the history
feat(expect): add ignoreCase option for toHaveURL

Fixes #30057
  • Loading branch information
KozynchenkoVS committed Apr 2, 2024
1 parent 81bcf2a commit e58a33a
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 2 deletions.
14 changes: 14 additions & 0 deletions docs/src/api/class-pageassertions.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,13 @@ The opposite of [`method: PageAssertions.toHaveURL`].

Expected URL string or RegExp.

### option: PageAssertions.NotToHaveURL.ignoreCase
* since: v1.44
* langs: js
- `ignoreCase` <[boolean]>

Whether to perform case-insensitive match. [`option: ignoreCase`] option takes precedence over the corresponding regular expression flag if specified.

### option: PageAssertions.NotToHaveURL.timeout = %%-csharp-java-python-assertions-timeout-%%
* since: v1.18

Expand Down Expand Up @@ -325,6 +332,13 @@ await Expect(Page).ToHaveURL(new Regex(".*checkout"));

Expected URL string or RegExp.

### option: PageAssertions.toHaveURL.ignoreCase
* since: v1.44
* langs: js
- `ignoreCase` <[boolean]>

Whether to perform case-insensitive match. [`option: ignoreCase`] option takes precedence over the corresponding regular expression flag if specified.

### option: PageAssertions.toHaveURL.timeout = %%-js-assertions-timeout-%%
* since: v1.18

Expand Down
4 changes: 2 additions & 2 deletions packages/playwright/src/matchers/matchers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -326,13 +326,13 @@ export function toHaveURL(
this: ExpectMatcherContext,
page: Page,
expected: string | RegExp,
options?: { timeout?: number },
options?: { ignoreCase?: boolean, timeout?: number },
) {
const baseURL = (page.context() as any)._options.baseURL;
expected = typeof expected === 'string' ? constructURLBasedOnBaseURL(baseURL, expected) : expected;
const locator = page.locator(':root') as LocatorEx;
return toMatchText.call(this, 'toHaveURL', locator, 'Locator', async (isNot, timeout) => {
const expectedText = toExpectedTextValues([expected]);
const expectedText = toExpectedTextValues([expected], { ignoreCase: options?.ignoreCase });
return await locator._expect('to.have.url', { expectedText, isNot, timeout });
}, expected, options);
}
Expand Down
6 changes: 6 additions & 0 deletions packages/playwright/types/test.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7210,6 +7210,12 @@ interface PageAssertions {
* @param options
*/
toHaveURL(urlOrRegExp: string|RegExp, options?: {
/**
* Whether to perform case-insensitive match. `ignoreCase` option takes precedence over the corresponding regular
* expression flag if specified.
*/
ignoreCase?: boolean;

/**
* Time to retry the assertion for in milliseconds. Defaults to `timeout` in `TestConfig.expect`.
*/
Expand Down
5 changes: 5 additions & 0 deletions tests/page/expect-misc.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,11 @@ test.describe('toHaveURL', () => {
const error = await expect(page).toHaveURL('wrong', { timeout: 1000 }).catch(e => e);
expect(error.message).toContain('expect.toHaveURL with timeout 1000ms');
});

test('support ignoreCase', async ({ page }) => {
await page.goto('data:text/html,<div>A</div>');
await expect(page).toHaveURL('DATA:teXT/HTml,<div>a</div>', { ignoreCase: true });
});
});

test.describe('toHaveAttribute', () => {
Expand Down

0 comments on commit e58a33a

Please sign in to comment.