Coder Social home page Coder Social logo

timotree3 / pptr-testing-library Goto Github PK

View Code? Open in Web Editor NEW

This project forked from testing-library/pptr-testing-library

0.0 1.0 0.0 876 KB

puppeteer + dom-testing-library = ๐Ÿ’–

License: MIT License

JavaScript 3.10% TypeScript 96.90%

pptr-testing-library's Introduction

pptr-testing-library

NPM Package Build Status Coverage 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('[email protected]')
// 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()
// ...

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
    • 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!

Related Puppeteer Test Utilities

LICENSE

MIT

pptr-testing-library's People

Contributors

abraham avatar dependabot[bot] avatar jrolfs avatar michaeldeboey avatar nickserv avatar patrickhulce avatar silviuaavram avatar timotree3 avatar umpox avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.