Skip to content

Commit 8c13f67

Browse files
authored
fix(test runner): remove folio/jest namespaces in expect matchers (#6930)
1 parent cfd49b5 commit 8c13f67

File tree

3 files changed

+9
-45
lines changed

3 files changed

+9
-45
lines changed

docs/src/test-advanced.md

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -467,16 +467,9 @@ For TypeScript, also add the following to `global.d.ts`. You don't need it for J
467467

468468
```js
469469
// global.d.ts
470-
declare namespace folio {
470+
declare namespace PlaywrightTest {
471471
interface Matchers<R> {
472472
toBeWithinRange(a: number, b: number): R;
473473
}
474474
}
475475
```
476-
477-
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`:
478-
479-
```js
480-
// global.d.ts
481-
import 'jest-extended';
482-
```

tests/playwright-test/expect.spec.ts

Lines changed: 3 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
import { test, expect } from './playwright-test-fixtures';
1818

19-
test('should be able to extend the expect matchers with test.extend in the folio config', async ({ runInlineTest }) => {
19+
test('should be able to call expect.extend in config', async ({ runInlineTest }) => {
2020
const result = await runInlineTest({
2121
'helper.ts': `
2222
pwt.expect.extend({
@@ -73,36 +73,12 @@ test('should work with default expect matchers', async ({runTSC}) => {
7373
expect(result.exitCode).toBe(0);
7474
});
7575

76-
test('should work with jest-community/jest-extended', async ({runTSC}) => {
76+
test('should work with custom PlaywrightTest namespace', async ({runTSC}) => {
7777
const result = await runTSC({
7878
'global.d.ts': `
7979
// Extracted example from their typings.
8080
// Reference: https://github.com/jest-community/jest-extended/blob/master/types/index.d.ts
81-
declare namespace jest {
82-
interface Matchers<R> {
83-
toBeEmpty(): R;
84-
}
85-
}
86-
`,
87-
'a.spec.ts': `
88-
const { test } = pwt;
89-
test.expect('').toBeEmpty();
90-
test.expect('hello').not.toBeEmpty();
91-
test.expect([]).toBeEmpty();
92-
test.expect(['hello']).not.toBeEmpty();
93-
test.expect({}).toBeEmpty();
94-
test.expect({ hello: 'world' }).not.toBeEmpty();
95-
`
96-
});
97-
expect(result.exitCode).toBe(0);
98-
});
99-
100-
test('should work with custom folio namespace', async ({runTSC}) => {
101-
const result = await runTSC({
102-
'global.d.ts': `
103-
// Extracted example from their typings.
104-
// Reference: https://github.com/jest-community/jest-extended/blob/master/types/index.d.ts
105-
declare namespace folio {
81+
declare namespace PlaywrightTest {
10682
interface Matchers<R> {
10783
toBeEmpty(): R;
10884
}

types/testExpect.d.ts

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import type { ExpectedAssertionsErrors } from 'expect/build/types';
1212
export declare type AsymmetricMatcher = Record<string, any>;
1313

1414
export declare type Expect = {
15-
<T = unknown>(actual: T): folio.Matchers<T>;
15+
<T = unknown>(actual: T): PlaywrightTest.Matchers<T>;
1616

1717
// Sourced from node_modules/expect/build/types.d.ts
1818
assertions(arg0: number): void;
@@ -30,27 +30,22 @@ export declare type Expect = {
3030
};
3131

3232
declare global {
33-
export namespace jest {
33+
export namespace PlaywrightTest {
3434
export interface Matchers<R> extends expect.Matchers<R> {
35-
36-
}
37-
}
38-
export namespace folio {
39-
export interface Matchers<R> extends jest.Matchers<R> {
4035
/**
4136
* If you know how to test something, `.not` lets you test its opposite.
4237
*/
43-
not: folio.Matchers<R>;
38+
not: PlaywrightTest.Matchers<R>;
4439
/**
4540
* Use resolves to unwrap the value of a fulfilled promise so any other
4641
* matcher can be chained. If the promise is rejected the assertion fails.
4742
*/
48-
resolves: folio.Matchers<Promise<R>>;
43+
resolves: PlaywrightTest.Matchers<Promise<R>>;
4944
/**
5045
* Unwraps the reason of a rejected promise so any other matcher can be chained.
5146
* If the promise is fulfilled the assertion fails.
5247
*/
53-
rejects: folio.Matchers<Promise<R>>;
48+
rejects: PlaywrightTest.Matchers<Promise<R>>;
5449
/**
5550
* Match snapshot
5651
*/

0 commit comments

Comments
 (0)