-
Notifications
You must be signed in to change notification settings - Fork 289
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Add toMatchElement method - Make all matchers wait before an element is present - All matchers accept an ElementHandle or a Page
- Loading branch information
Showing
23 changed files
with
758 additions
and
211 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
packages/expect-puppeteer/src/matchers/notToMatchElement.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { defaultOptions, getContext } from '../utils' | ||
|
||
async function notToMatchElement( | ||
instance, | ||
selector, | ||
{ text, ...options } = {}, | ||
) { | ||
options = defaultOptions(options) | ||
|
||
const { page, handle } = await getContext(instance, () => document) | ||
|
||
try { | ||
await page.waitForFunction( | ||
(handle, selector, text) => { | ||
const elements = handle.querySelectorAll(selector) | ||
if (text !== undefined) { | ||
return [...elements].every( | ||
({ textContent }) => !textContent.match(text), | ||
) | ||
} | ||
|
||
return elements.length === 0 | ||
}, | ||
options, | ||
handle, | ||
selector, | ||
text, | ||
) | ||
} catch (error) { | ||
throw new Error( | ||
`Element ${selector}${ | ||
text !== undefined ? ` (text: "${text}") ` : ' ' | ||
}found`, | ||
) | ||
} | ||
} | ||
|
||
export default notToMatchElement |
Oops, something went wrong.