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

pptr-testing-library

Package Overview
Dependencies
Maintainers
1
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

pptr-testing-library

puppeteer + dom-testing-library

  • 0.8.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
28K
decreased by-13.58%
Maintainers
1
Weekly downloads
 
Created
Source

pptr-testing-library

NPM Package GitHub Actions status Dependencies Discord

puppeteer + @testing-library/dom = 💖

All your favorite user-centric querying functions from @testing-library/react & @testing-library/library available from Puppeteer!

Install

npm install --save-dev pptr-testing-library

Use

const puppeteer = require('puppeteer')
const {getDocument, queries, waitFor} = require('pptr-testing-library')

const {getByTestId, getByLabelText} = queries

const browser = await puppeteer.launch()
const page = await browser.newPage()

// Grab ElementHandle for document
const $document = await getDocument(page)
// Your favorite query methods are available
const $form = await getByTestId($document, 'my-form')
// returned elements are ElementHandles too!
const $email = await getByLabelText($form, 'Email')
// interact with puppeteer like usual
await $email.type('pptr@example.com')
// waiting works too!
await waitFor(() => getByText($document, 'Loading...'))

A little too un-puppeteer for you? We've got prototype-mucking covered too :)

const puppeteer = require('puppeteer')
require('pptr-testing-library/extend')

const browser = await puppeteer.launch()
const page = await browser.newPage()

// getDocument is added to prototype of Page
const $document = await page.getDocument()
// query methods are added directly to prototype of ElementHandle
const $form = await $document.getByTestId('my-form')
// destructing works if you explicitly call getQueriesForElement
const {getByText} = $form.getQueriesForElement()
// ...

Version Compat

Puppeteer Versionpptr-testing-library Version
17+>0.8.0
<170.7.x

API

Unique methods, not part of @testing-library/dom

  • getDocument(page: puppeteer.Page): ElementHandle - get an ElementHandle for the document
  • wait(conditionFn: () => {}): Promise<{}> - wait for the condition to not throw (wrapper around waitForExpect)

@testing-library/dom API. All get*/query* methods are supported.

  • getQueriesForElement(handle: ElementHandle): ElementHandle & QueryUtils - extend the input object with the query API and return it
  • getNodeText(handle: ElementHandle): Promise<string> - get the text content of the element
  • queries: QueryUtils - the query subset of @testing-library/dom exports
    • queryByPlaceholderText
    • queryAllByPlaceholderText
    • getByPlaceholderText
    • getAllByPlaceholderText
    • findByPlaceholderText
    • findAllByPlaceholderText
    • queryByText
    • queryAllByText
    • getByText
    • getAllByText
    • findByText
    • findAllByText
    • queryByLabelText
    • queryAllByLabelText
    • getByLabelText
    • getAllByLabelText
    • findByLabelText
    • findAllByLabelText
    • queryByAltText
    • queryAllByAltText
    • getByAltText
    • getAllByAltText
    • findByAltText
    • findAllByAltText
    • queryByTestId
    • queryAllByTestId
    • getByTestId
    • getAllByTestId
    • findByTestId
    • findAllByTestId
    • queryByTitle
    • queryAllByTitle
    • getByTitle
    • getAllByTitle
    • findByTitle
    • findAllByTitle
    • queryByRole
    • queryAllByRole
    • getByRole
    • getAllByRole
    • findByRole
    • findAllByRole
    • queryByDisplayValue,
    • queryAllByDisplayValue,
    • getByDisplayValue,
    • getAllByDisplayValue,
    • findByDisplayValue,
    • findAllByDisplayValue,

Known Limitations

  • Async utilities waitForElement, waitForElementToBeRemoved and waitForDomChange are not exposed. Consider using a find* query.
  • fireEvent method is not exposed, use puppeteer's built-ins instead.
  • expect assertion extensions are not available.

Special Thanks

@testing-library/dom of course!

LICENSE

MIT

Keywords

FAQs

Package last updated on 07 Mar 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

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