Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.
TypeScript automationchromechromiume2e-testingelectronend-to-end-testingfirefoxjavascriptplaywrighttesttest-automationtestingtesting-toolswebwebkit
chore: fix soft after poll (#22642)
Pavel Feldman7fdd7a20fb04
diff --git a/packages/playwright-test/src/matchers/expect.ts b/packages/playwright-test/src/matchers/expect.tsindex ea1192c568..a3dd1b57e6 100644--- a/packages/playwright-test/src/matchers/expect.ts+++ b/packages/playwright-test/src/matchers/expect.ts@@ -115,7 +115,7 @@ function createMatchers(actual: unknown, info: ExpectMetaInfo): any {}function createExpect(info: ExpectMetaInfo) {- const expect: Expect = new Proxy(expectLibrary, {+ const expectInstance: Expect = new Proxy(expectLibrary, {apply: function(target: any, thisArg: any, argumentsList: [unknown, ExpectMessage?]) {const [actual, messageOrOptions] = argumentsList;const message = isString(messageOrOptions) ? messageOrOptions : messageOrOptions?.message || info.message;@@ -126,19 +126,29 @@ function createExpect(info: ExpectMetaInfo) {newInfo.generator = actual as any;}return createMatchers(actual, newInfo);- }- });+ },- expect.soft = (actual: unknown, messageOrOptions?: ExpectMessage) => {- return expect.configure({ soft: true })(actual, messageOrOptions) as any;- };+ get: function(target: any, property: string) {+ if (property === 'configure')+ return configure;- expect.poll = (actual: unknown, messageOrOptions?: ExpectMessage & { timeout?: number, intervals?: number[] }) => {- const poll = isString(messageOrOptions) ? {} : messageOrOptions || {};- return expect.configure({ poll })(actual, messageOrOptions) as any;- };+ if (property === 'soft') {+ return (actual: unknown, messageOrOptions?: ExpectMessage) => {+ return configure({ soft: true })(actual, messageOrOptions) as any;+ };+ }++ if (property === 'poll') {+ return (actual: unknown, messageOrOptions?: ExpectMessage & { timeout?: number, intervals?: number[] }) => {+ const poll = isString(messageOrOptions) ? {} : messageOrOptions || {};+ return configure({ poll })(actual, messageOrOptions) as any;+ };+ }+ return expectLibrary[property];+ },+ });- expect.configure = (configuration: { message?: string, timeout?: number, soft?: boolean, poll?: boolean | { timeout?: number, intervals?: number[] } }) => {+ const configure = (configuration: { message?: string, timeout?: number, soft?: boolean, poll?: boolean | { timeout?: number, intervals?: number[] } }) => {const newInfo = { ...info };if ('message' in configuration)newInfo.message = configuration.message;@@ -156,7 +166,7 @@ function createExpect(info: ExpectMetaInfo) {return createExpect(newInfo);};- return expect;+ return expectInstance;}export const expect: Expect = createExpect({});diff --git a/tests/playwright-test/expect-configure.spec.ts b/tests/playwright-test/expect-configure.spec.tsindex 2463881da7..741155f6e3 100644--- a/tests/playwright-test/expect-configure.spec.ts+++ b/tests/playwright-test/expect-configure.spec.ts@@ -158,3 +158,16 @@ test('should configure soft poll', async ({ runInlineTest }) => {expect(result.exitCode).toBe(1);expect(result.outputLines).toEqual(['woof-woof']);});++test('should configure soft after poll', async ({ runInlineTest }) => {+ const result = await runInlineTest({+ 'a.spec.ts': `+ import { test, expect } from '@playwright/test';+ test('should pass', async () => {+ await expect.poll(() => true).toBe(true);+ expect.soft(1).toBe(1);+ });+ `+ });+ expect(result.exitCode).toBe(0);+});