# puppeteer-mock

> Build a bridge between Puppeteer and your favourite HTTP mocking library

Latest version **0.1.0** (published 2021-02-03) · MIT license · 0 weekly downloads

## Install

```sh
npm install puppeteer-mock
pnpm add puppeteer-mock
yarn add puppeteer-mock
bun add puppeteer-mock
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.0 |
| Published | 2021-02-03 |
| First published | 2021-02-03 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 6.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | florpor |
| Maintainers | florpor |
| Keywords | puppeteer, mock, mocking, http, https, test, tests |

## Links

- npm: https://www.npmjs.com/package/puppeteer-mock
- Repository: https://github.com/florpor/puppeteer-mock
- Issues: https://github.com/florpor/puppeteer-mock/issues
- npm.io page: https://npm.io/package/puppeteer-mock

## Dependencies (2)

- [sinon](https://npm.io/package/sinon.md) ^9.2.4
- [puppeteer](https://npm.io/package/puppeteer.md) ^5.5.0

## Alternatives

- [duck](https://npm.io/package/duck.md) — 4.2M weekly downloads
- [ava](https://npm.io/package/ava.md) — 560.2K weekly downloads
- [storybook-addon-module-mock](https://npm.io/package/storybook-addon-module-mock.md) — 71.7K weekly downloads
- [vest](https://npm.io/package/vest.md) — 50.1K weekly downloads
- [@ethereum-waffle/mock-contract](https://npm.io/package/@ethereum-waffle/mock-contract.md) — 40.0K weekly downloads

## Recent versions

- 0.1.0 (latest) — 2021-02-03

## README

# puppeteer-mock

Build a bridge between Puppeteer and your favourite HTTP mocking library

puppeteer-mock makes the testing of Puppeteer-backed code easy by enabling the mocking of page responses which arrive at the headless browser.

puppeteer-mock should work with any library which mocks Node.js's http/https module responses and is not dependent on a specific mocking library.

## Installation

```bash
$ npm install --save-dev puppeteer-mock
```

## Usage

You can enable puppeteer-mock simply by calling its activate function:

```js
const puppeteerMock = require('puppeteer-mock');

puppeteerMock.activate();
```

**NOTE:** puppeteer-mock does not do the actual HTTP response mocking. You will need to use some library such as [nock](https://github.com/nock/nock) for that. What puppeteer-mock does is the routing of Puppeteer requests through Node.js's http/https modules so that the responses can be mocked using any supported HTTP mocking library.

A recommended way to use puppeteer-mock is to activate it in your tests' setup hook and deactivate it in your teardown hook:

```js
const puppeteerMock = require('puppeteer-mock');

describe('test suite', function() {
    beforeEach(function () {
        // activate puppeteer-mock
        if (!puppeteerMock.isActive())
            puppeteerMock.activate();
    }); 

    afterEach(function() {
        // restore puppeteer requests
        puppeteerMock.deactivate();
    });

    it('some test', function() {
        // test code goes here
    });
});
```

## API

**puppeteerMock.activate()**

Activate puppeteer-mock to route Puppeteer requests through the library.

**puppeteerMock.deactivate()**

Deactivate puppeteer-mock and have Puppeteer requests routed normally.

**puppeteerMock.isActive()**

Check if puppeteer-mock is currently active.

---
_Source: https://npm.io/package/puppeteer-mock · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
