Working ignoreCase
This commit is contained in:
parent
efd3ab04a2
commit
883bb5ff1d
|
|
@ -21,7 +21,7 @@ import { expectTypes, callLogText } from '../util';
|
||||||
import { toBeTruthy } from './toBeTruthy';
|
import { toBeTruthy } from './toBeTruthy';
|
||||||
import { toEqual } from './toEqual';
|
import { toEqual } from './toEqual';
|
||||||
import { toMatchText } from './toMatchText';
|
import { toMatchText } from './toMatchText';
|
||||||
import { constructURLBasedOnBaseURL, isRegExp, isString, isTextualMimeType, pollAgainstDeadline, serializeExpectedTextValues, urlMatches } from 'playwright-core/lib/utils';
|
import { isRegExp, isString, isTextualMimeType, pollAgainstDeadline, serializeExpectedTextValues, urlMatches } from 'playwright-core/lib/utils';
|
||||||
import { currentTestInfo } from '../common/globals';
|
import { currentTestInfo } from '../common/globals';
|
||||||
import { TestInfoImpl } from '../worker/testInfo';
|
import { TestInfoImpl } from '../worker/testInfo';
|
||||||
import type { ExpectMatcherState } from '../../types/test';
|
import type { ExpectMatcherState } from '../../types/test';
|
||||||
|
|
@ -388,7 +388,7 @@ export function toHaveTitle(
|
||||||
}, expected, options);
|
}, expected, options);
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function toHaveURL2(
|
export async function toHaveURL(
|
||||||
this: ExpectMatcherState,
|
this: ExpectMatcherState,
|
||||||
page: Page,
|
page: Page,
|
||||||
expected: string | RegExp | ((url: URL) => boolean),
|
expected: string | RegExp | ((url: URL) => boolean),
|
||||||
|
|
@ -408,10 +408,34 @@ export async function toHaveURL2(
|
||||||
const timeout = options?.timeout ?? this.timeout;
|
const timeout = options?.timeout ?? this.timeout;
|
||||||
let conditionSucceeded = false;
|
let conditionSucceeded = false;
|
||||||
try {
|
try {
|
||||||
await page.mainFrame().waitForURL(url => {
|
await page.mainFrame().waitForURL(
|
||||||
const baseURL = (page.context() as any)._options.baseURL;
|
url => {
|
||||||
return !this.isNot === urlMatches(baseURL, url.toString(), expected);
|
const baseURL: string | undefined = (page.context() as any)._options
|
||||||
}, { timeout });
|
.baseURL;
|
||||||
|
if (options?.ignoreCase) {
|
||||||
|
return (
|
||||||
|
!this.isNot ===
|
||||||
|
urlMatches(
|
||||||
|
baseURL?.toLocaleLowerCase(),
|
||||||
|
url.toString().toLocaleLowerCase(),
|
||||||
|
typeof expected === 'string'
|
||||||
|
? expected.toLocaleLowerCase()
|
||||||
|
: expected,
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
!this.isNot ===
|
||||||
|
urlMatches(
|
||||||
|
baseURL,
|
||||||
|
url.toString(),
|
||||||
|
expected,
|
||||||
|
)
|
||||||
|
);
|
||||||
|
},
|
||||||
|
{ timeout },
|
||||||
|
);
|
||||||
|
|
||||||
conditionSucceeded = true;
|
conditionSucceeded = true;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
|
@ -440,21 +464,6 @@ export async function toHaveURL2(
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export function toHaveURL(
|
|
||||||
this: ExpectMatcherState,
|
|
||||||
page: Page,
|
|
||||||
expected: string | RegExp,
|
|
||||||
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 = serializeExpectedTextValues([expected], { ignoreCase: options?.ignoreCase });
|
|
||||||
return await locator._expect('to.have.url', { expectedText, isNot, timeout });
|
|
||||||
}, expected, options);
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function toBeOK(
|
export async function toBeOK(
|
||||||
this: ExpectMatcherState,
|
this: ExpectMatcherState,
|
||||||
response: APIResponseEx
|
response: APIResponseEx
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue