Comments (9)
So I'm trying to do this with an element handle and it doesn't work as expected.
Example:
const element = await page.$('#element');
expect(element).toMatch("MyText")
I looked at the code and it tries to access .textContent
and afiak you need to do something like the OP described to get the textContent:
const textProperty = await element.getProperty("textContent");
const textContent = await textProperty.jsonValue();
from jest-puppeteer.
expect(element).toMatch("MyText")
?
from jest-puppeteer.
Oh hey sorry @neoziro could you please re-open the issue?
That throws an error with string value must be a string.
:
FAIL test\end-to-end\Sample.test.ts (23.415s)
● TestName › selecting
expect(string)[.not].toMatch(expected)
string value must be a string.
Received:
object: {"_client": {"_callbacks": [Map], "_connection": [Connection], "_events": [Object], "_eventsCount": 21, "_lastId": 23, "_maxListeners": undefined, "_sessionId": "3C0BCAE419DF693A81907AB87C8FC1A6:1", "_targetId": "3C0BCAE419DF693A81907AB87C8FC1A6", "domain": null}, "_context": {"_client": [CDPSession], "_contextId": 2, "_frame": [Frame], "_objectHandleFactory": [Function bound createJSHandle]}, "_disposed": false, "_frameManager": {"_client": [CDPSession], "_contextIdToContext": [Map], "_events": [Object], "_eventsCount": 3, "_frames": [Map], "_mainFrame": [Frame], "_maxListeners": undefined, "_page": [Page], "domain": null}, "_page": {"_client": [CDPSession], "_coverage": [Coverage], "_defaultNavigationTimeout": 30000, "_emulationManager": [EmulationManager], "_events": [Object], "_eventsCount": 3, "_frameManager": [FrameManager], "_ignoreHTTPSErrors": false, "_keyboard": [Keyboard], "_maxListeners": undefined, "_mouse": [Mouse], "_networkManager": [NetworkManager], "_pageBindings": [Map], "_screenshotTaskQueue": [TaskQueue], "_target": [Target], "_touchscreen": [Touchscreen], "_tracing": [Tracing], "_viewport": [Object], "domain": null}, "_remoteObject": {"className": "HTMLSpanElement", "description": "span", "objectId": "{\"injectedScriptId\":2,\"id\":3}", "subtype": "node", "type": "object"}}
81 | // Assert
82 | const editableElement = await page.waitForSelector(selectorEditable);
> 83 | await expect(editableElement).toMatch("NOPE");
from jest-puppeteer.
Do you use expect-puppeteer
? https://github.com/smooth-code/jest-puppeteer/blob/master/packages/expect-puppeteer/README.md#toMatch
from jest-puppeteer.
I do, and other parts of it work correctly.
Perhaps the issue is that it's taking in an element instead of the page? I haven't had time to look too closely...
from jest-puppeteer.
It should work element too, maybe the detection is failing, it is actually a bug.
from jest-puppeteer.
@JoshuaKGoldberg still relevant?
from jest-puppeteer.
I've switched from Puppeteer to Selenium so I have no idea. I'll just close the issue in the hopes that nobody will report it again. Thanks!
from jest-puppeteer.
Hello @scragg0x, I think you forgot await
in front of expect(element).toMatch("MyText")
. In the linked code, we are in a watch function, so it is correct to call textContent
directly on the element.
from jest-puppeteer.
Related Issues (20)
- JSHandle@node is not supported HOT 6
- `spawnd` package should have `exit` as a dependency, not a devDependency
- Dependency Errors Using `npm i` HOT 2
- Cannot find module 'node:stream' on fresh install HOT 1
- Compiler errors importing `JestPuppeteerConfig` interface HOT 2
- Compiler errors extending `PuppeteerEnvironment`
- Compiler errors accessing `PuppeteerEnvironment` globals HOT 1
- Jest preset not working with latest jest and jest-puppeteer HOT 6
- Snapshot serializers added with `expect.addSnapshotSerializer` are not used HOT 3
- Remove Warning On New Headless Setting HOT 5
- Many browser windows open when running tests HOT 3
- [jest-dev-server] not working server.usedPortAction: 'ignore' config when running React application with react-scripts
- Invariant: WORKERS_COUNT not found HOT 4
- @types/expect-puppeteer no such type toMatchTextContent HOT 1
- Using jest-puppeteer with nx HOT 4
- How can I launch jest-puppeteer with args? HOT 1
- Regression: `injectGlobals:false` no longer supported ("Cannot convert undefined or null to object") HOT 1
- Puppeteer 21 regression: `[object Object] is not supported` HOT 4
- Is @types/jest-environment-puppeteer still required? HOT 3
- jest-dev-server - "kill" missing in "usedPortAction" type definition HOT 1
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 jest-puppeteer.