expect-playwright
Advanced tools
Comparing version 0.1.1 to 0.2.1
import { PageWaitForSelectorOptions } from "playwright-core"; | ||
export interface PlaywrightMatchers<R> { | ||
/** | ||
* Will check if the element's textContent on the page determined by the selector includes the given text. | ||
*/ | ||
toHaveText(selector: string, value: string, options?: PageWaitForSelectorOptions): Promise<R>; | ||
/** | ||
* Will check if the element's value includes the given text. | ||
*/ | ||
toHaveText(value: string, options?: PageWaitForSelectorOptions): Promise<R>; | ||
/** | ||
* Will compare the element's textContent on the page determined by the selector with the given text. | ||
*/ | ||
toEqualText(selector: string, value: string, options?: PageWaitForSelectorOptions): Promise<R>; | ||
/** | ||
* Will compare the element's textContent by the given text. | ||
*/ | ||
toEqualText(value: string, options?: PageWaitForSelectorOptions): Promise<R>; | ||
/** | ||
* Will ensure that the element is one the page in a given timeout (default 1 second). | ||
*/ | ||
toHaveSelector(selector: string, options?: PageWaitForSelectorOptions): Promise<R>; | ||
/** | ||
* Will compare the element's value on the page determined by the selector with the given value. | ||
*/ | ||
toEqualValue(selector: string, value: string, options?: PageWaitForSelectorOptions): Promise<R>; | ||
/** | ||
* Will compare element's value with the given value. | ||
*/ | ||
toEqualValue(value: string, options?: PageWaitForSelectorOptions): Promise<R>; | ||
} | ||
@@ -10,0 +33,0 @@ |
@@ -9,2 +9,3 @@ "use strict"; | ||
const toHaveSelector_1 = __importDefault(require("./toHaveSelector")); | ||
const toEqualValue_1 = __importDefault(require("./toEqualValue")); | ||
exports.default = { | ||
@@ -14,2 +15,3 @@ toHaveText: toHaveText_1.default, | ||
toHaveSelector: toHaveSelector_1.default, | ||
toEqualValue: toEqualValue_1.default, | ||
}; |
@@ -12,3 +12,3 @@ "use strict"; | ||
pass: true, | ||
message: () => `${utils_1.quote(expectedValue)} does not equal ${utils_1.quote(actualTextContent)}.` | ||
message: () => `${utils_1.quote(expectedValue)} does equal ${utils_1.quote(actualTextContent)}.` | ||
}; | ||
@@ -15,0 +15,0 @@ } |
{ | ||
"name": "expect-playwright", | ||
"version": "0.1.1", | ||
"version": "0.2.1", | ||
"main": "lib/index.js", | ||
@@ -5,0 +5,0 @@ "types": "./global.d.ts", |
@@ -56,2 +56,3 @@ # expect-playwright | ||
- [toEqualText](#toEqualText) | ||
- [toEqualValue](#toEqualValue) | ||
@@ -90,3 +91,3 @@ ### toHaveSelector | ||
Or by passing an Playwright [ElementHandle]: | ||
Or by passing a Playwright [ElementHandle]: | ||
@@ -122,3 +123,3 @@ **expect(page: [ElementHandle]).toHaveText(value: string, options?: [PageWaitForSelectorOptions](https://github.com/microsoft/playwright/blob/master/docs/api.md#pagewaitforselectorselector-options))** | ||
Or by passing an Playwright [ElementHandle]: | ||
Or by passing a Playwright [ElementHandle]: | ||
@@ -134,2 +135,25 @@ **expect(page: [ElementHandle]).toEqualText(value: string, options?: [PageWaitForSelectorOptions](https://github.com/microsoft/playwright/blob/master/docs/api.md#pagewaitforselectorselector-options))** | ||
### toEqualValue | ||
This function checks if the `value` of a given element is the same as the provided value. | ||
You can do this via a selector or the element directly: | ||
**expect(page: [Page]).toEqualValue(selector: string, value: string, options?: [PageWaitForSelectorOptions](https://github.com/microsoft/playwright/blob/master/docs/api.md#pagewaitforselectorselector-options))** | ||
```javascript | ||
await expect(page).toEqualValue("#my-element", "Playwright") | ||
``` | ||
Or by passing a Playwright [ElementHandle]: | ||
**expect(page: [ElementHandle]).toEqualValue(value: string, options?: [PageWaitForSelectorOptions](https://github.com/microsoft/playwright/blob/master/docs/api.md#pagewaitforselectorselector-options))** | ||
```javascript | ||
const element = await page.$('#my-element'); | ||
await expect(element).toEqualValue("Playwright") | ||
``` | ||
By default it waits 1 second for the element which you can overwrite via the options. | ||
## Examples | ||
@@ -136,0 +160,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
190
17170
246