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

jest-puppeteer

Package Overview
Dependencies
Maintainers
0
Versions
65
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

jest-puppeteer

Run your tests using Jest & Puppeteer.

  • 10.1.4
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
175K
increased by3.51%
Maintainers
0
Weekly downloads
 
Created

What is jest-puppeteer?

jest-puppeteer is a Jest preset that allows you to use Puppeteer, a headless Chrome Node API, for end-to-end testing. It simplifies the setup and configuration needed to use Puppeteer with Jest, enabling you to write tests that interact with web pages in a browser-like environment.

What are jest-puppeteer's main functionalities?

Setup and Teardown

jest-puppeteer provides a simple way to configure global setup and teardown scripts, as well as a custom test environment for running Puppeteer tests.

module.exports = {
  globalSetup: './setup.js',
  globalTeardown: './teardown.js',
  testEnvironment: './puppeteer_environment.js'
};

Writing Tests

You can write tests using Jest's syntax, and use Puppeteer's API to interact with the web page. In this example, the test navigates to Google's homepage and checks if the text 'google' is present.

describe('Google', () => {
  beforeAll(async () => {
    await page.goto('https://google.com');
  });

  it('should display "google" text on page', async () => {
    await expect(page).toMatch('google');
  });
});

Custom Matchers

jest-puppeteer allows you to extend Jest with custom matchers that can be used to assert conditions specific to Puppeteer. This example shows how to create a custom matcher to check if an element's text includes a specific string.

expect.extend({
  async toMatchText(received, argument) {
    const text = await received.evaluate(el => el.textContent);
    if (text.includes(argument)) {
      return {
        message: () => `expected ${text} to include ${argument}`,
        pass: true
      };
    } else {
      return {
        message: () => `expected ${text} to include ${argument}`,
        pass: false
      };
    }
  }
});

Other packages similar to jest-puppeteer

Keywords

FAQs

Package last updated on 26 Oct 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