Comments (4)
Happy to hear you solved your problem. As you can see, I deleted my comment with the recommendation because I really don't want anybody who doesn't understand the consequences of importing a private package to see it. But you seem to be aware of that, so have fun! :D I'll close the issue.
from playwright.
As a workaround you can save original matchers before extending the expect and later call them from your implementation:
const originalToHaveText = (baseExpect as any).toHaveText;
const dateExpect = baseExpect.extend({
async toHaveText(this: ExpectMatcherState, date: Date, expected: string | RegExp, options?: { ignoreCase?: boolean, timeout?: number }): Promise<MatcherReturnType> {
...
} else {
originalToHaveText.call(baseExpect(date as Locator), expected, options);
}
...
},
});
would that work for your scenario?
from playwright.
I can't get that to work either ... originalToHaveText
is (...u)=>new i(!1,...u)
which seems to return an AsymmetricMatcher
when called:
i {
'$$typeof': Symbol(jest.asymmetricMatcher),
sample: [ [ 'Node.js', 'Python', 'Java', '.NET' ], undefined ],
inverse: false
}
Not sure what to do with this object? Need to build a MatcherReturnType
from that somehow.
(I also tried to save (baseExpect({}) as any).toHaveText
, but it seems the dummy value
is captured so I can't provide the actual Locator
when calling it later.)
from playwright.
Didn't work as-is for me (Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: Package subpath './lib/matchers/matchers' is not defined by "exports" in .../package.json
, but I got it working in the import-internal-matchers branch of the demo repo.
It's a bit tricky to actually get the path of matchers.js
reliably (playwright
might not be hoisted), but the demo code is currently working for all combinations of npm/yarn/pnpm, esm/cjs and Node 16/18/20/22 (at least on macOS).
I think I will go with this approach and cross my fingers it doesn't break too often. Thanks for the help!
PS. It would obviously be totally awesome if @playwright/test
had a public export of all the built-in matchers (including toBe
etc from the bundled expect
library) so we could reuse and extend them in a supported way. Getting the MatcherReturnType
right is quite some work.
from playwright.
Related Issues (20)
- [Feature]: SlowMo for specific tests HOT 1
- [Feature]: 'Expand All' button - ability to expand all tests in --ui version
- [Bug]: Running one set of tests, changing JUNIT output, then running as second set of tests, results in only one test file with original output file/dir HOT 1
- [Bug]: Runtime tags not shown in the report. HOT 1
- [Regression]: Incorrect value in case pass list of objects as args to fixture HOT 3
- [Bug]: Top-level await doesn't work in playwright.config.ts HOT 2
- Reg saving multiple reports and viewing.
- [Issue] screenshots' filename is renamed unexpectedly HOT 1
- [internal]: screenshot instead of snapshot polishing HOT 1
- [Bug]: HOT 1
- [Bug]: Page.screenshot: Timeout 30000ms exceeded HOT 2
- [Bug]: Test timeout - 'AfterEach' hook time isn't included in the test timeout. HOT 1
- [Bug]: generateLocator depends on timing to not produce locators that violate strict mode HOT 2
- [Bug]: @playwright/experimental-ct-react fails to render if the root element is a React fragment HOT 1
- [Bug]: Some web elements are not displayed when using viewport parameters HOT 5
- [Docs]: Getting started - VS Code HOT 4
- [Bug]: WebKit/macOS - "no-preference" color scheme falls back to the system's one HOT 3
- [Feature]: merge Playwright Inspector into trace view
- page.evaluate returns empty object HOT 6
- [Bug]: Network mocking does not work for initial request when page opened via extension API `chrome.tabs.create()`
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from playwright.