expect-puppeteer
Advanced tools
Comparing version 4.4.0 to 5.0.0
@@ -6,2 +6,18 @@ # Change Log | ||
# [5.0.0](https://github.com/smooth-code/jest-puppeteer/tree/master/packages/expect-puppeteer/compare/v4.4.0...v5.0.0) (2021-04-16) | ||
### Bug Fixes | ||
* toFill doesn't empty contents when given an empty string ([#381](https://github.com/smooth-code/jest-puppeteer/tree/master/packages/expect-puppeteer/issues/381)) ([964b9a2](https://github.com/smooth-code/jest-puppeteer/tree/master/packages/expect-puppeteer/commit/964b9a276c0e0219e55cfa0db752d65da93d41b3)) | ||
### Features | ||
* support XPATH selectors ([#321](https://github.com/smooth-code/jest-puppeteer/tree/master/packages/expect-puppeteer/issues/321)) ([949027b](https://github.com/smooth-code/jest-puppeteer/tree/master/packages/expect-puppeteer/commit/949027b1332e270fad78eda10fd1a92c56abe1b5)) | ||
# [4.4.0](https://github.com/smooth-code/jest-puppeteer/tree/master/packages/expect-puppeteer/compare/v4.3.0...v4.4.0) (2019-12-18) | ||
@@ -8,0 +24,0 @@ |
@@ -113,4 +113,4 @@ "use strict"; | ||
const jestMatchers = originalExpect(actual, ...args); | ||
return _extends({}, jestMatchers, {}, matchers, { | ||
not: _extends({}, jestMatchers.not, {}, matchers.not) | ||
return _extends({}, jestMatchers, matchers, { | ||
not: _extends({}, jestMatchers.not, matchers.not) | ||
}); | ||
@@ -117,0 +117,0 @@ } |
@@ -23,2 +23,3 @@ "use strict"; | ||
}); | ||
await element.press('Backspace'); | ||
await element.type(value, { | ||
@@ -25,0 +26,0 @@ delay |
@@ -10,2 +10,4 @@ "use strict"; | ||
function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); } | ||
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; } | ||
@@ -21,2 +23,6 @@ | ||
options = (0, _options.defaultOptions)(options); | ||
selector = selector instanceof Object ? _extends({}, selector) : { | ||
type: 'css', | ||
value: selector | ||
}; | ||
const { | ||
@@ -46,4 +52,28 @@ page, | ||
const elements = [...handle.querySelectorAll(selector)].filter(isVisible); | ||
let nodes = []; | ||
switch (selector.type) { | ||
case 'xpath': | ||
{ | ||
const xpathResults = document.evaluate(selector.value, handle); | ||
let currentXpathResult = xpathResults.iterateNext(); | ||
while (currentXpathResult) { | ||
nodes.push(currentXpathResult); | ||
currentXpathResult = xpathResults.iterateNext(); | ||
} | ||
break; | ||
} | ||
case 'css': | ||
nodes = handle.querySelectorAll(selector.value); | ||
break; | ||
default: | ||
throw new Error(`${selector.type} is not implemented`); | ||
} | ||
const elements = [...nodes].filter(isVisible); | ||
if (regexp !== null) { | ||
@@ -68,3 +98,3 @@ const [, pattern, flags] = regexp.match(/\/(.*)\/(.*)?/); | ||
} catch (error) { | ||
throw (0, _utils.enhanceError)(error, `Element ${selector}${text !== null || regexp !== null ? ` (text: "${text || regexp}") ` : ' '}not found`); | ||
throw (0, _utils.enhanceError)(error, `Element ${selector.value}${text !== null || regexp !== null ? ` (text: "${text || regexp}") ` : ' '}not found`); | ||
} | ||
@@ -71,0 +101,0 @@ |
@@ -33,4 +33,4 @@ "use strict"; | ||
const defaultOptions = options => _extends({}, getDefaultOptions(), {}, options); | ||
const defaultOptions = options => _extends({}, getDefaultOptions(), options); | ||
exports.defaultOptions = defaultOptions; |
{ | ||
"name": "expect-puppeteer", | ||
"description": "Assertion toolkit for Puppeteer.", | ||
"version": "4.4.0", | ||
"version": "5.0.0", | ||
"main": "lib/index.js", | ||
@@ -21,3 +21,3 @@ "repository": "https://github.com/smooth-code/jest-puppeteer/tree/master/packages/expect-puppeteer", | ||
"scripts": { | ||
"prebuild": "rm -rf lib/", | ||
"prebuild": "rimraf lib/", | ||
"build": "babel --config-file ../../babel.config.js -d lib --ignore \"**/*.test.js\" src", | ||
@@ -27,3 +27,3 @@ "dev": "yarn build --watch", | ||
}, | ||
"gitHead": "c28ecb7729bef11cee25e91b16d75fb34f81f07a" | ||
"gitHead": "153d47bf5a733f6525b018d50c2cae841d606d3f" | ||
} |
@@ -82,3 +82,3 @@ # expect-puppeteer | ||
- `instance` <[Page]|[ElementHandle]> Context | ||
- `selector` <[string]> A [selector] to click on | ||
- `selector` <[string]|[MatchSelector](#MatchSelector)> A [selector] or a [MatchSelector](#MatchSelector) to click on. | ||
- `options` <[Object]> Optional parameters | ||
@@ -92,2 +92,3 @@ - `button` <"left"|"right"|"middle"> Defaults to `left`. | ||
await expect(page).toClick('button', { text: 'Home' }) | ||
await expect(page).toClick({ type: 'xpath', value: '\\a' }, { text: 'Click' }) | ||
``` | ||
@@ -176,3 +177,3 @@ | ||
// Click on the third column link | ||
await expect(row).toClick('td:nth-child(2) a') | ||
await expect(row).toClick('td:nth-child(3) a') | ||
``` | ||
@@ -209,2 +210,14 @@ | ||
### <a name="MatchSelector"></a>{type: [string], value: [string]} | ||
An object used as parameter in order to select an element. | ||
- `type` <"xpath"|"css"> The type of the selector | ||
- `value` <[string]> The value of the selector | ||
```js | ||
{type:'css', value:'form[name="myForm"]'} | ||
{type:'xpath', value:'.\\a'} | ||
``` | ||
## Configure default options | ||
@@ -211,0 +224,0 @@ |
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
42307
516
254
1