address comments
This commit is contained in:
parent
2d5c7c6707
commit
62054a3b36
|
|
@ -15,9 +15,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export const expect: typeof import('../../bundles/expect/node_modules/expect/build').expect = require('./expectBundleImpl').expect;
|
export const expect: typeof import('../../bundles/expect/node_modules/expect/build').expect = require('./expectBundleImpl').expect;
|
||||||
export type ExpectMatcherContext = import('../../bundles/expect/node_modules/expect/build').MatcherContext;
|
|
||||||
export const EXPECTED_COLOR: typeof import('../../bundles/expect/node_modules/jest-matcher-utils/build').EXPECTED_COLOR = require('./expectBundleImpl').EXPECTED_COLOR;
|
export const EXPECTED_COLOR: typeof import('../../bundles/expect/node_modules/jest-matcher-utils/build').EXPECTED_COLOR = require('./expectBundleImpl').EXPECTED_COLOR;
|
||||||
export const INVERTED_COLOR: typeof import('../../bundles/expect/node_modules/jest-matcher-utils/build').INVERTED_COLOR = require('./expectBundleImpl').INVERTED_COLOR;
|
export const INVERTED_COLOR: typeof import('../../bundles/expect/node_modules/jest-matcher-utils/build').INVERTED_COLOR = require('./expectBundleImpl').INVERTED_COLOR;
|
||||||
export const RECEIVED_COLOR: typeof import('../../bundles/expect/node_modules/jest-matcher-utils/build').RECEIVED_COLOR = require('./expectBundleImpl').RECEIVED_COLOR;
|
export const RECEIVED_COLOR: typeof import('../../bundles/expect/node_modules/jest-matcher-utils/build').RECEIVED_COLOR = require('./expectBundleImpl').RECEIVED_COLOR;
|
||||||
export const matcherErrorMessage: typeof import('../../bundles/expect/node_modules/jest-matcher-utils/build').matcherErrorMessage = require('./expectBundleImpl').matcherErrorMessage;
|
|
||||||
export const printReceived: typeof import('../../bundles/expect/node_modules/jest-matcher-utils/build').printReceived = require('./expectBundleImpl').printReceived;
|
export const printReceived: typeof import('../../bundles/expect/node_modules/jest-matcher-utils/build').printReceived = require('./expectBundleImpl').printReceived;
|
||||||
|
|
|
||||||
|
|
@ -58,7 +58,6 @@ import {
|
||||||
RECEIVED_COLOR,
|
RECEIVED_COLOR,
|
||||||
printReceived,
|
printReceived,
|
||||||
} from '../common/expectBundle';
|
} from '../common/expectBundle';
|
||||||
export type { ExpectMatcherContext } from '../common/expectBundle';
|
|
||||||
import { zones } from 'playwright-core/lib/utils';
|
import { zones } from 'playwright-core/lib/utils';
|
||||||
import { TestInfoImpl } from '../worker/testInfo';
|
import { TestInfoImpl } from '../worker/testInfo';
|
||||||
import { ExpectError } from './matcherHint';
|
import { ExpectError } from './matcherHint';
|
||||||
|
|
@ -132,12 +131,11 @@ function createExpect(info: ExpectMetaInfo) {
|
||||||
const wrappedMatchers: any = {};
|
const wrappedMatchers: any = {};
|
||||||
Object.entries(matchers).forEach(([name, matcher]) => {
|
Object.entries(matchers).forEach(([name, matcher]) => {
|
||||||
wrappedMatchers[name] = function(...args: any[]) {
|
wrappedMatchers[name] = function(...args: any[]) {
|
||||||
const { isNot, promise, utils, expand } = this;
|
const { isNot, promise, utils } = this;
|
||||||
const newThis: ExpectMatcherState = {
|
const newThis: ExpectMatcherState = {
|
||||||
isNot,
|
isNot,
|
||||||
promise,
|
promise,
|
||||||
utils,
|
utils,
|
||||||
expand,
|
|
||||||
timeout: currentExpectTimeout({})
|
timeout: currentExpectTimeout({})
|
||||||
};
|
};
|
||||||
return (matcher as any).call(newThis, ...args);
|
return (matcher as any).call(newThis, ...args);
|
||||||
|
|
|
||||||
|
|
@ -22,11 +22,12 @@ import {
|
||||||
printReceivedStringContainExpectedResult,
|
printReceivedStringContainExpectedResult,
|
||||||
printReceivedStringContainExpectedSubstring
|
printReceivedStringContainExpectedSubstring
|
||||||
} from './expect';
|
} from './expect';
|
||||||
import { EXPECTED_COLOR, matcherErrorMessage } from '../common/expectBundle';
|
import { EXPECTED_COLOR } from '../common/expectBundle';
|
||||||
import type { ExpectMatcherState } from '../../types/test';
|
import type { ExpectMatcherState } from '../../types/test';
|
||||||
import { kNoElementsFoundError, matcherHint } from './matcherHint';
|
import { kNoElementsFoundError, matcherHint } from './matcherHint';
|
||||||
import type { MatcherResult } from './matcherHint';
|
import type { MatcherResult } from './matcherHint';
|
||||||
import type { Locator } from 'playwright-core';
|
import type { Locator } from 'playwright-core';
|
||||||
|
import { colors } from 'playwright-core/lib/utilsBundle';
|
||||||
|
|
||||||
export async function toMatchText(
|
export async function toMatchText(
|
||||||
this: ExpectMatcherState,
|
this: ExpectMatcherState,
|
||||||
|
|
@ -48,15 +49,12 @@ export async function toMatchText(
|
||||||
!(typeof expected === 'string') &&
|
!(typeof expected === 'string') &&
|
||||||
!(expected && typeof expected.test === 'function')
|
!(expected && typeof expected.test === 'function')
|
||||||
) {
|
) {
|
||||||
throw new Error(
|
// Same format as jest's matcherErrorMessage
|
||||||
matcherErrorMessage(
|
throw new Error([
|
||||||
matcherHint(this, receiver, matcherName, receiver, expected, matcherOptions),
|
matcherHint(this, receiver, matcherName, receiver, expected, matcherOptions),
|
||||||
`${EXPECTED_COLOR(
|
`${colors.bold('Matcher error')}: ${EXPECTED_COLOR('expected',)} value must be a string or regular expression`,
|
||||||
'expected',
|
this.utils.printWithType('Expected', expected, this.utils.printExpected)
|
||||||
)} value must be a string or regular expression`,
|
].join('\n\n'));
|
||||||
this.utils.printWithType('Expected', expected, this.utils.printExpected),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const timeout = options.timeout ?? this.timeout;
|
const timeout = options.timeout ?? this.timeout;
|
||||||
|
|
|
||||||
12
packages/playwright/types/test.d.ts
vendored
12
packages/playwright/types/test.d.ts
vendored
|
|
@ -6510,10 +6510,20 @@ export interface ExpectMatcherUtils {
|
||||||
}
|
}
|
||||||
|
|
||||||
export type ExpectMatcherState = {
|
export type ExpectMatcherState = {
|
||||||
|
/**
|
||||||
|
* Wehther this matcher was called with the negated .not modifier.
|
||||||
|
*/
|
||||||
isNot: boolean;
|
isNot: boolean;
|
||||||
|
/**
|
||||||
|
* - 'rejects' if matcher was called with the promise .rejects modifier
|
||||||
|
* - 'resolves' if matcher was called with the promise .resolves modifier
|
||||||
|
* - '' if matcher was not called with a promise modifier
|
||||||
|
*/
|
||||||
promise: 'rejects' | 'resolves' | '';
|
promise: 'rejects' | 'resolves' | '';
|
||||||
utils: ExpectMatcherUtils;
|
utils: ExpectMatcherUtils;
|
||||||
expand: boolean;
|
/**
|
||||||
|
* Timeout in milliseconds for the assertion to be fulfilled.
|
||||||
|
*/
|
||||||
timeout: number;
|
timeout: number;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1012,7 +1012,7 @@ test('should expose timeout to custom matchers', async ({ runInlineTest, runTSC
|
||||||
import type { ExpectMatcherState, MatcherReturnType } from '@playwright/test';
|
import type { ExpectMatcherState, MatcherReturnType } from '@playwright/test';
|
||||||
import { test, expect as base } from '@playwright/test';
|
import { test, expect as base } from '@playwright/test';
|
||||||
|
|
||||||
const expect = base.extend<{assertTimeout: (this: ExpectMatcherState, page: any, value: number) => MatcherReturnType}>({
|
const expect = base.extend({
|
||||||
assertTimeout(page: any, value: number) {
|
assertTimeout(page: any, value: number) {
|
||||||
const pass = this.timeout === value;
|
const pass = this.timeout === value;
|
||||||
return {
|
return {
|
||||||
|
|
|
||||||
12
utils/generate_types/overrides-test.d.ts
vendored
12
utils/generate_types/overrides-test.d.ts
vendored
|
|
@ -358,10 +358,20 @@ export interface ExpectMatcherUtils {
|
||||||
}
|
}
|
||||||
|
|
||||||
export type ExpectMatcherState = {
|
export type ExpectMatcherState = {
|
||||||
|
/**
|
||||||
|
* Wehther this matcher was called with the negated .not modifier.
|
||||||
|
*/
|
||||||
isNot: boolean;
|
isNot: boolean;
|
||||||
|
/**
|
||||||
|
* - 'rejects' if matcher was called with the promise .rejects modifier
|
||||||
|
* - 'resolves' if matcher was called with the promise .resolves modifier
|
||||||
|
* - '' if matcher was not called with a promise modifier
|
||||||
|
*/
|
||||||
promise: 'rejects' | 'resolves' | '';
|
promise: 'rejects' | 'resolves' | '';
|
||||||
utils: ExpectMatcherUtils;
|
utils: ExpectMatcherUtils;
|
||||||
expand: boolean;
|
/**
|
||||||
|
* Timeout in milliseconds for the assertion to be fulfilled.
|
||||||
|
*/
|
||||||
timeout: number;
|
timeout: number;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue