mirror of
https://github.com/microsoft/playwright.git
synced 2025-06-26 21:40:17 +00:00
fix(expect): throw unsupported error when using this.equals() in expect (#31723)
This commit is contained in:
parent
e11c0c0cbb
commit
ed6abf86c7
@ -308,6 +308,8 @@ test('amount', async () => {
|
|||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Compatibility with expect library
|
||||||
|
|
||||||
:::note
|
:::note
|
||||||
Do not confuse Playwright's `expect` with the [`expect` library](https://jestjs.io/docs/expect). The latter is not fully integrated with Playwright test runner, so make sure to use Playwright's own `expect`.
|
Do not confuse Playwright's `expect` with the [`expect` library](https://jestjs.io/docs/expect). The latter is not fully integrated with Playwright test runner, so make sure to use Playwright's own `expect`.
|
||||||
:::
|
:::
|
||||||
|
|||||||
@ -138,6 +138,7 @@ function createExpect(info: ExpectMetaInfo) {
|
|||||||
utils,
|
utils,
|
||||||
timeout: currentExpectTimeout()
|
timeout: currentExpectTimeout()
|
||||||
};
|
};
|
||||||
|
(newThis as any).equals = throwUnsupportedExpectMatcherError;
|
||||||
return (matcher as any).call(newThis, ...args);
|
return (matcher as any).call(newThis, ...args);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@ -183,6 +184,10 @@ function createExpect(info: ExpectMetaInfo) {
|
|||||||
return expectInstance;
|
return expectInstance;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function throwUnsupportedExpectMatcherError() {
|
||||||
|
throw new Error('It looks like you are using custom expect matchers that are not compatible with Playwright. See https://aka.ms/playwright/expect-compatibility');
|
||||||
|
}
|
||||||
|
|
||||||
expectLibrary.setState({ expand: false });
|
expectLibrary.setState({ expand: false });
|
||||||
|
|
||||||
const customAsyncMatchers = {
|
const customAsyncMatchers = {
|
||||||
|
|||||||
@ -1039,3 +1039,27 @@ test('should expose timeout to custom matchers', async ({ runInlineTest, runTSC
|
|||||||
expect(result.failed).toBe(0);
|
expect(result.failed).toBe(0);
|
||||||
expect(result.passed).toBe(2);
|
expect(result.passed).toBe(2);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('should throw error when using .equals()', async ({ runInlineTest }) => {
|
||||||
|
const result = await runInlineTest({
|
||||||
|
'helper.ts': `
|
||||||
|
import { test as base, expect } from '@playwright/test';
|
||||||
|
expect.extend({
|
||||||
|
toBeWithinRange(received, floor, ceiling) {
|
||||||
|
this.equals(1, 2);
|
||||||
|
},
|
||||||
|
});
|
||||||
|
export const test = base;
|
||||||
|
`,
|
||||||
|
'expect-test.spec.ts': `
|
||||||
|
import { test } from './helper';
|
||||||
|
test('numeric ranges', () => {
|
||||||
|
test.expect(() => {
|
||||||
|
test.expect(100).toBeWithinRange(90, 110);
|
||||||
|
}).toThrowError('It looks like you are using custom expect matchers that are not compatible with Playwright. See https://aka.ms/playwright/expect-compatibility');
|
||||||
|
});
|
||||||
|
`
|
||||||
|
});
|
||||||
|
expect(result.exitCode).toBe(0);
|
||||||
|
expect(result.passed).toBe(1);
|
||||||
|
});
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user