Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: fallback expect.extend to legacy #32795

Merged
merged 1 commit into from
Sep 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions packages/playwright/src/matchers/expect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,7 @@ function createExpect(info: ExpectMetaInfo, prefix: string[], customMatchers: Re
const wrappedMatchers: any = {};
const extendedMatchers: any = { ...customMatchers };
for (const [name, matcher] of Object.entries(matchers)) {
const key = qualifiedMatcherName(qualifier, name);
wrappedMatchers[key] = function(...args: any[]) {
wrappedMatchers[name] = function(...args: any[]) {
const { isNot, promise, utils } = this;
const newThis: ExpectMatcherState = {
isNot,
Expand All @@ -152,6 +151,8 @@ function createExpect(info: ExpectMetaInfo, prefix: string[], customMatchers: Re
(newThis as any).equals = throwUnsupportedExpectMatcherError;
return (matcher as any).call(newThis, ...args);
};
const key = qualifiedMatcherName(qualifier, name);
wrappedMatchers[key] = wrappedMatchers[name];
Object.defineProperty(wrappedMatchers[key], 'name', { value: name });
extendedMatchers[name] = wrappedMatchers[key];
}
Expand Down
36 changes: 35 additions & 1 deletion tests/playwright-test/expect.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1068,4 +1068,38 @@ test('expect.extend should be immutable', async ({ runInlineTest }) => {
'foo',
'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