chore: replace regex check with isRegExp from playwright-core/lib/utils

This commit is contained in:
Pengoose 2024-11-12 09:12:04 +09:00
parent bc85868e63
commit 4141467ee5

View file

@ -19,6 +19,7 @@ import { matcherHint } from './matcherHint';
import type { MatcherResult } from './matcherHint'; import type { MatcherResult } from './matcherHint';
import type { ExpectMatcherState } from '../../types/test'; import type { ExpectMatcherState } from '../../types/test';
import type { Locator } from 'playwright-core'; import type { Locator } from 'playwright-core';
import { isRegExp } from 'playwright-core/lib/utils';
// Omit colon and one or more spaces, so can call getLabelPrinter. // Omit colon and one or more spaces, so can call getLabelPrinter.
const EXPECTED_LABEL = 'Expected'; const EXPECTED_LABEL = 'Expected';
@ -62,7 +63,7 @@ export async function toEqual<T>(
} else if (Array.isArray(expected) && Array.isArray(received)) { } else if (Array.isArray(expected) && Array.isArray(received)) {
const normalizedExpected = expected.map((exp, index) => { const normalizedExpected = expected.map((exp, index) => {
const rec = received[index]; const rec = received[index];
if (exp instanceof RegExp) if (isRegExp(exp))
return exp.test(rec) ? rec : exp; return exp.test(rec) ? rec : exp;
return exp; return exp;