From 8c13f679b73b7b7166fb885073b0f3e71dbf583d Mon Sep 17 00:00:00 2001 From: Dmitry Gozman Date: Mon, 7 Jun 2021 08:02:01 -0700 Subject: [PATCH] fix(test runner): remove folio/jest namespaces in expect matchers (#6930) --- docs/src/test-advanced.md | 9 +-------- tests/playwright-test/expect.spec.ts | 30 +++------------------------- types/testExpect.d.ts | 15 +++++--------- 3 files changed, 9 insertions(+), 45 deletions(-) diff --git a/docs/src/test-advanced.md b/docs/src/test-advanced.md index 4b5e79c6e2..0bd516b3f3 100644 --- a/docs/src/test-advanced.md +++ b/docs/src/test-advanced.md @@ -467,16 +467,9 @@ For TypeScript, also add the following to `global.d.ts`. You don't need it for J ```js // global.d.ts -declare namespace folio { +declare namespace PlaywrightTest { interface Matchers { toBeWithinRange(a: number, b: number): R; } } ``` - -To import expect matching libraries like [jest-extended](https://github.com/jest-community/jest-extended#installation) you can import it from your `global.d.ts`: - -```js -// global.d.ts -import 'jest-extended'; -``` diff --git a/tests/playwright-test/expect.spec.ts b/tests/playwright-test/expect.spec.ts index 51ec0d3af9..233228bb8f 100644 --- a/tests/playwright-test/expect.spec.ts +++ b/tests/playwright-test/expect.spec.ts @@ -16,7 +16,7 @@ import { test, expect } from './playwright-test-fixtures'; -test('should be able to extend the expect matchers with test.extend in the folio config', async ({ runInlineTest }) => { +test('should be able to call expect.extend in config', async ({ runInlineTest }) => { const result = await runInlineTest({ 'helper.ts': ` pwt.expect.extend({ @@ -73,36 +73,12 @@ test('should work with default expect matchers', async ({runTSC}) => { expect(result.exitCode).toBe(0); }); -test('should work with jest-community/jest-extended', async ({runTSC}) => { +test('should work with custom PlaywrightTest namespace', async ({runTSC}) => { const result = await runTSC({ 'global.d.ts': ` // Extracted example from their typings. // Reference: https://github.com/jest-community/jest-extended/blob/master/types/index.d.ts - declare namespace jest { - interface Matchers { - toBeEmpty(): R; - } - } - `, - 'a.spec.ts': ` - const { test } = pwt; - test.expect('').toBeEmpty(); - test.expect('hello').not.toBeEmpty(); - test.expect([]).toBeEmpty(); - test.expect(['hello']).not.toBeEmpty(); - test.expect({}).toBeEmpty(); - test.expect({ hello: 'world' }).not.toBeEmpty(); - ` - }); - expect(result.exitCode).toBe(0); -}); - -test('should work with custom folio namespace', async ({runTSC}) => { - const result = await runTSC({ - 'global.d.ts': ` - // Extracted example from their typings. - // Reference: https://github.com/jest-community/jest-extended/blob/master/types/index.d.ts - declare namespace folio { + declare namespace PlaywrightTest { interface Matchers { toBeEmpty(): R; } diff --git a/types/testExpect.d.ts b/types/testExpect.d.ts index 43ad05351f..ab1935c1ac 100644 --- a/types/testExpect.d.ts +++ b/types/testExpect.d.ts @@ -12,7 +12,7 @@ import type { ExpectedAssertionsErrors } from 'expect/build/types'; export declare type AsymmetricMatcher = Record; export declare type Expect = { - (actual: T): folio.Matchers; + (actual: T): PlaywrightTest.Matchers; // Sourced from node_modules/expect/build/types.d.ts assertions(arg0: number): void; @@ -30,27 +30,22 @@ export declare type Expect = { }; declare global { - export namespace jest { + export namespace PlaywrightTest { export interface Matchers extends expect.Matchers { - - } - } - export namespace folio { - export interface Matchers extends jest.Matchers { /** * If you know how to test something, `.not` lets you test its opposite. */ - not: folio.Matchers; + not: PlaywrightTest.Matchers; /** * Use resolves to unwrap the value of a fulfilled promise so any other * matcher can be chained. If the promise is rejected the assertion fails. */ - resolves: folio.Matchers>; + resolves: PlaywrightTest.Matchers>; /** * Unwraps the reason of a rejected promise so any other matcher can be chained. * If the promise is fulfilled the assertion fails. */ - rejects: folio.Matchers>; + rejects: PlaywrightTest.Matchers>; /** * Match snapshot */