-
Notifications
You must be signed in to change notification settings - Fork 29
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How do I write unit tests or e2e tests? #68
Comments
This library doesn't really interact with any specific test runner, so how you decide to chunk your tests is up to you. Here's an example with const puppeteer = require('puppeteer')
const {getDocument, queries, waitFor} = require('pptr-testing-library')
const {getByTestId, getByLabelText} = queries
describe('e2e tests', () => {
let browser
let page
let $document
beforeAll(async () => {
browser = await puppeteer.launch()
page = await browser.newPage()
})
it('loads the page', async () => {
await page.goto('https://example.com')
// Grab ElementHandle for document
$document = await getDocument(page)
})
it('fills out the form', async () => {
// 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...'))
const $submit = await getByLabelText(
})
it('submitted the data successfully', async () => {
const $header = await getByTestId($document, 'header')
expect(await $header.evaluate(el => el.textContent)).toEqual('Success!')
})
}) |
PR welcome for anyone that wants to contribute something more substantive :) |
How do I add the test methods? |
Is there a page that explains how to set up? |
Are you asking how to setup basic jest/mocha tests at all? |
Yes I’m using jest for unit tests. Wondering how to get it to work with puppeteer too |
I've got this now. but it won't run. It doesn't find "it()"
My package.json looks like this:
I get this error:
|
Ok so actually it works. lol. but puppetter is not opening an actual browser. Is there a way to enable that? |
How can I do this:
It throws an error. |
What error? |
The examples don’t show any kind of test code. Like “it”
The text was updated successfully, but these errors were encountered: