chore: fallback expect.extend to legacy (#32795)
This commit is contained in:
parent
a4cea0c208
commit
755edfba5b
|
|
@ -140,8 +140,7 @@ function createExpect(info: ExpectMetaInfo, prefix: string[], customMatchers: Re
|
||||||
const wrappedMatchers: any = {};
|
const wrappedMatchers: any = {};
|
||||||
const extendedMatchers: any = { ...customMatchers };
|
const extendedMatchers: any = { ...customMatchers };
|
||||||
for (const [name, matcher] of Object.entries(matchers)) {
|
for (const [name, matcher] of Object.entries(matchers)) {
|
||||||
const key = qualifiedMatcherName(qualifier, name);
|
wrappedMatchers[name] = function(...args: any[]) {
|
||||||
wrappedMatchers[key] = function(...args: any[]) {
|
|
||||||
const { isNot, promise, utils } = this;
|
const { isNot, promise, utils } = this;
|
||||||
const newThis: ExpectMatcherState = {
|
const newThis: ExpectMatcherState = {
|
||||||
isNot,
|
isNot,
|
||||||
|
|
@ -152,6 +151,8 @@ function createExpect(info: ExpectMetaInfo, prefix: string[], customMatchers: Re
|
||||||
(newThis as any).equals = throwUnsupportedExpectMatcherError;
|
(newThis as any).equals = throwUnsupportedExpectMatcherError;
|
||||||
return (matcher as any).call(newThis, ...args);
|
return (matcher as any).call(newThis, ...args);
|
||||||
};
|
};
|
||||||
|
const key = qualifiedMatcherName(qualifier, name);
|
||||||
|
wrappedMatchers[key] = wrappedMatchers[name];
|
||||||
Object.defineProperty(wrappedMatchers[key], 'name', { value: name });
|
Object.defineProperty(wrappedMatchers[key], 'name', { value: name });
|
||||||
extendedMatchers[name] = wrappedMatchers[key];
|
extendedMatchers[name] = wrappedMatchers[key];
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1069,3 +1069,37 @@ test('expect.extend should be immutable', async ({ runInlineTest }) => {
|
||||||
'bar',
|
'bar',
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('expect.extend should fall back to legacy behavior', async ({ runInlineTest }) => {
|
||||||
|
const result = await runInlineTest({
|
||||||
|
'expect-test.spec.ts': `
|
||||||
|
import { test, expect } from '@playwright/test';
|
||||||
|
expect.extend({
|
||||||
|
toFoo() {
|
||||||
|
console.log('%%foo');
|
||||||
|
return { pass: true };
|
||||||
|
}
|
||||||
|
});
|
||||||
|
expect.extend({
|
||||||
|
toFoo() {
|
||||||
|
console.log('%%foo2');
|
||||||
|
return { pass: true };
|
||||||
|
}
|
||||||
|
});
|
||||||
|
expect.extend({
|
||||||
|
toBar() {
|
||||||
|
console.log('%%bar');
|
||||||
|
return { pass: true };
|
||||||
|
}
|
||||||
|
});
|
||||||
|
test('logs', () => {
|
||||||
|
expect().toFoo();
|
||||||
|
expect().toBar();
|
||||||
|
});
|
||||||
|
`
|
||||||
|
});
|
||||||
|
expect(result.outputLines).toEqual([
|
||||||
|
'foo2',
|
||||||
|
'bar',
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue