Fix tests

This commit is contained in:
Adam Gastineau 2025-01-23 12:34:40 -08:00
parent ded2fe2f5e
commit a7559f7b8c
2 changed files with 7 additions and 5 deletions

View file

@ -18,7 +18,7 @@ import type { Page } from 'playwright-core';
import type { ExpectMatcherState } from '../../types/test';
import { EXPECTED_COLOR, printReceived } from '../common/expectBundle';
import { matcherHint, type MatcherResult } from './matcherHint';
import { urlMatches } from 'playwright-core/lib/utils';
import { constructURLBasedOnBaseURL, urlMatches } from 'playwright-core/lib/utils';
import { colors } from 'playwright-core/lib/utilsBundle';
import { printReceivedStringContainExpectedResult, printReceivedStringContainExpectedSubstring } from './expect';
@ -51,13 +51,12 @@ export async function toHaveURL(
}
const timeout = options?.timeout ?? this.timeout;
const baseURL: string | undefined = (page.context() as any)._options.baseURL;
let conditionSucceeded = false;
let lastCheckedURLString: string | undefined = undefined;
try {
await page.mainFrame().waitForURL(
url => {
const baseURL: string | undefined = (page.context() as any)._options
.baseURL;
lastCheckedURLString = url.toString();
if (options?.ignoreCase) {
@ -96,7 +95,9 @@ export async function toHaveURL(
this,
matcherName,
expression,
expected,
typeof expected === 'string'
? constructURLBasedOnBaseURL(baseURL, expected)
: expected,
lastCheckedURLString,
this.isNot,
true,

View file

@ -561,11 +561,12 @@ test('should support toHaveURL predicate', async ({ runInlineTest }) => {
'playwright.config.js': `module.exports = { expect: { timeout: 1000 } }`,
'a.test.ts': `
import { test, expect } from '@playwright/test';
import { stripVTControlCharacters } from 'node:util';
test('predicate', async ({ page }) => {
await page.goto('data:text/html,<div>A</div>');
const error = await expect(page).toHaveURL('data:text/html,<div>B</div>').catch(e => e);
expect(error.message).toContain('expect.toHaveURL with timeout 1000ms');
expect(stripVTControlCharacters(error.message)).toContain('Timed out 1000ms waiting for expect(page).toHaveURL(expected)');
expect(error.message).toContain('data:text/html,<div>');
});
`,