Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

expect-playwright

Package Overview
Dependencies
Maintainers
2
Versions
23
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

expect-playwright - npm Package Compare versions

Comparing version 0.4.1 to 0.5.0

lib/matchers/toMatchText/index.js

17

global.d.ts

@@ -27,2 +27,3 @@ // copied into our codebase for autocompletion purposes

* Will check if the element's textContent on the page determined by the selector includes the given text.
* @deprecated Use toMatchText instead
*/

@@ -36,5 +37,21 @@ toHaveText(

* Will check if the element's value includes the given text.
* @deprecated Use toMatchText instead
*/
toHaveText(value: string, options?: PageWaitForSelectorOptions): Promise<R>
/**
* Will check if the element's textContent on the page determined by the selector matches the given pattern.
*/
toMatchText(
selector: string,
pattern: RegExp | string,
options?: PageWaitForSelectorOptions
): Promise<R>
/**
* Will check if the element's value matches the given pattern.
*/
toMatchText(
pattern: RegExp | string,
options?: PageWaitForSelectorOptions
): Promise<R>
/**
* Will compare the element's textContent on the page determined by the selector with the given text.

@@ -41,0 +58,0 @@ */

3

lib/matchers/toEqualUrl/index.js

@@ -5,3 +5,4 @@ "use strict";

const toEqualUrl = async function (page, expectedUrl) {
const actualUrl = page.url();
const frame = await utils_1.getFrame(page);
const actualUrl = frame.url();
return {

@@ -8,0 +9,0 @@ pass: actualUrl === expectedUrl,

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const utils_1 = require("../utils");
/**
* Will check if the element's textContent on the page determined by the selector includes the given text.
* @deprecated Use toMatchText instead
*/
const toHaveText = async function (...args) {

@@ -5,0 +9,0 @@ try {

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getMessage = exports.quote = exports.getElementText = exports.detectExpectType = void 0;
const ExpectTypePage = "Page";
const ExpectTypeElementHandle = "ElementHandle";
exports.getMessage = exports.quote = exports.getElementText = exports.getFrame = exports.detectExpectType = void 0;
const detectExpectType = (value) => {
const className = value.constructor.name;
switch (className) {
case "Page":
return ExpectTypePage;
case "ElementHandle":
return ExpectTypeElementHandle;
default:
throw new Error(`could not recognize type: ${className}`);
const type = {
Page: 1 /* Page */,
Frame: 0 /* Frame */,
ElementHandle: 2 /* ElementHandle */,
}[className];
if (type === undefined) {
throw new Error(`could not recognize type: ${className}`);
}
return type;
};
exports.detectExpectType = detectExpectType;
const isElementHandle = (value) => exports.detectExpectType(value) === 2 /* ElementHandle */;
const getFrame = (value) => isElementHandle(value) ? value.contentFrame() : value;
exports.getFrame = getFrame;
const lastElementHasType = (args, type) => typeof args[args.length - 1] === type;

@@ -38,3 +40,3 @@ const getSelectorOptions = (args) => {

if (args.length === 2) {
if (type === ExpectTypeElementHandle) {
if (type === 2 /* ElementHandle */) {
const iframe = await args[0].contentFrame();

@@ -47,5 +49,5 @@ const elem = iframe ? await iframe.$("body") : args[0];

}
const page = args[0];
const frame = args[0];
return {
elementHandle: (await page.$("body")),
elementHandle: (await frame.$("body")),
expectedValue: args[1],

@@ -59,7 +61,7 @@ };

const selector = args[1];
if (type === ExpectTypePage) {
const page = args[0];
if (type === 1 /* Page */ || type === 0 /* Frame */) {
const frame = args[0];
const selectorOptions = getSelectorOptions(args);
try {
await page.waitForSelector(selector, selectorOptions);
await frame.waitForSelector(selector, selectorOptions);
}

@@ -70,7 +72,7 @@ catch (err) {

return {
elementHandle: (await page.$(selector)),
elementHandle: (await frame.$(selector)),
expectedValue: args[2],
};
}
if (type === ExpectTypeElementHandle) {
if (type === 2 /* ElementHandle */) {
const iframe = await args[0].contentFrame();

@@ -77,0 +79,0 @@ const elem = iframe ? await iframe.$("body") : args[0];

{
"name": "expect-playwright",
"version": "0.4.1",
"version": "0.5.0",
"main": "lib/index.js",

@@ -5,0 +5,0 @@ "types": "./global.d.ts",

@@ -61,3 +61,3 @@ # expect-playwright

- [toHaveSelectorCount](#toHaveSelectorCount)
- [toHaveText](#toHaveText)
- [toMatchText](#toMatchText)
- [toEqualText](#toEqualText)

@@ -116,12 +116,13 @@ - [toEqualValue](#toEqualValue)

### toHaveText
### toMatchText
This function checks if the `textContent` of a given element contains the provided value.
This function checks if the `textContent` of a given element matches the provided pattern.
You can do this via a selector on the whole page:
**expect(page: [Page]).toHaveText(selector: string, value: string, options?: [PageWaitForSelectorOptions](https://playwright.dev/docs/api/class-page/#pagewaitforselectorselector-options))**
**expect(page: [Page]).toMatchText(selector: string, pattern: RegExp | string, options?: [PageWaitForSelectorOptions](https://playwright.dev/docs/api/class-page/#pagewaitforselectorselector-options))**
```javascript
await expect(page).toHaveText("#my-element", "MyValue")
await expect(page).toMatchText("#my-element", "MyPattern")
await expect(page).toMatchText("#my-element", /MyPattern/)
```

@@ -131,6 +132,7 @@

**expect(page: [Page]).toHaveText(value: string)**
**expect(page: [Page]).toMatchText(pattern: RegExp | string)**
```javascript
await expect(page).toHaveText("Playwright")
await expect(page).toMatchText(/Playwright/)
await expect(page).toMatchText("Playwright")
```

@@ -137,0 +139,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc