fix(test runner): remove folio/jest namespaces in expect matchers (#6930)
This commit is contained in:
parent
cfd49b5c01
commit
8c13f679b7
|
|
@ -467,16 +467,9 @@ For TypeScript, also add the following to `global.d.ts`. You don't need it for J
|
||||||
|
|
||||||
```js
|
```js
|
||||||
// global.d.ts
|
// global.d.ts
|
||||||
declare namespace folio {
|
declare namespace PlaywrightTest {
|
||||||
interface Matchers<R> {
|
interface Matchers<R> {
|
||||||
toBeWithinRange(a: number, b: number): R;
|
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';
|
|
||||||
```
|
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,7 @@
|
||||||
|
|
||||||
import { test, expect } from './playwright-test-fixtures';
|
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({
|
const result = await runInlineTest({
|
||||||
'helper.ts': `
|
'helper.ts': `
|
||||||
pwt.expect.extend({
|
pwt.expect.extend({
|
||||||
|
|
@ -73,36 +73,12 @@ test('should work with default expect matchers', async ({runTSC}) => {
|
||||||
expect(result.exitCode).toBe(0);
|
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({
|
const result = await runTSC({
|
||||||
'global.d.ts': `
|
'global.d.ts': `
|
||||||
// Extracted example from their typings.
|
// Extracted example from their typings.
|
||||||
// Reference: https://github.com/jest-community/jest-extended/blob/master/types/index.d.ts
|
// Reference: https://github.com/jest-community/jest-extended/blob/master/types/index.d.ts
|
||||||
declare namespace jest {
|
declare namespace PlaywrightTest {
|
||||||
interface Matchers<R> {
|
|
||||||
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 {
|
|
||||||
interface Matchers<R> {
|
interface Matchers<R> {
|
||||||
toBeEmpty(): R;
|
toBeEmpty(): R;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
15
types/testExpect.d.ts
vendored
15
types/testExpect.d.ts
vendored
|
|
@ -12,7 +12,7 @@ import type { ExpectedAssertionsErrors } from 'expect/build/types';
|
||||||
export declare type AsymmetricMatcher = Record<string, any>;
|
export declare type AsymmetricMatcher = Record<string, any>;
|
||||||
|
|
||||||
export declare type Expect = {
|
export declare type Expect = {
|
||||||
<T = unknown>(actual: T): folio.Matchers<T>;
|
<T = unknown>(actual: T): PlaywrightTest.Matchers<T>;
|
||||||
|
|
||||||
// Sourced from node_modules/expect/build/types.d.ts
|
// Sourced from node_modules/expect/build/types.d.ts
|
||||||
assertions(arg0: number): void;
|
assertions(arg0: number): void;
|
||||||
|
|
@ -30,27 +30,22 @@ export declare type Expect = {
|
||||||
};
|
};
|
||||||
|
|
||||||
declare global {
|
declare global {
|
||||||
export namespace jest {
|
export namespace PlaywrightTest {
|
||||||
export interface Matchers<R> extends expect.Matchers<R> {
|
export interface Matchers<R> extends expect.Matchers<R> {
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
export namespace folio {
|
|
||||||
export interface Matchers<R> extends jest.Matchers<R> {
|
|
||||||
/**
|
/**
|
||||||
* If you know how to test something, `.not` lets you test its opposite.
|
* If you know how to test something, `.not` lets you test its opposite.
|
||||||
*/
|
*/
|
||||||
not: folio.Matchers<R>;
|
not: PlaywrightTest.Matchers<R>;
|
||||||
/**
|
/**
|
||||||
* Use resolves to unwrap the value of a fulfilled promise so any other
|
* 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.
|
* matcher can be chained. If the promise is rejected the assertion fails.
|
||||||
*/
|
*/
|
||||||
resolves: folio.Matchers<Promise<R>>;
|
resolves: PlaywrightTest.Matchers<Promise<R>>;
|
||||||
/**
|
/**
|
||||||
* Unwraps the reason of a rejected promise so any other matcher can be chained.
|
* Unwraps the reason of a rejected promise so any other matcher can be chained.
|
||||||
* If the promise is fulfilled the assertion fails.
|
* If the promise is fulfilled the assertion fails.
|
||||||
*/
|
*/
|
||||||
rejects: folio.Matchers<Promise<R>>;
|
rejects: PlaywrightTest.Matchers<Promise<R>>;
|
||||||
/**
|
/**
|
||||||
* Match snapshot
|
* Match snapshot
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue