@jomaxx/jest-polly
TypeScript icon, indicating that this package has built-in type declarations

2.1.0 • Public • Published

@jomaxx/jest-polly

An opinionated integration between Jest and Polly.js.

Usage

Install

yarn add --dev jest @jomaxx/jest-polly
# or with NPM
npm install --save-dev jest @jomaxx/jest-polly

Use in all tests

In your package.json

{
  "jest": {
    "setupFilesAfterEnv": ["@jomaxx/jest-polly"]
  }
}

Or in jest.config.js

module.exports = {
  setupFilesAfterEnv: ['@jomaxx/jest-polly'],
};

Use in a single test

In my.test.js

import '@jomaxx/jest-polly';
import fetch from 'node-fetch';

test('is ok', async () => {
  const response = await fetch('https://www.google.com/', { method: 'HEAD' });
  expect(response.ok).toBe(true);
});

Using the polly instance

Use the polly instance to change default behavior. Read docs.

import { polly } from '@jomaxx/jest-polly';
import fetch from 'node-fetch';

polly.server
  .any('https://www.google.com/')
  .intercept((req, res) => res.sendStatus(500));

test('is not ok', async () => {
  const response = await fetch('https://www.google.com/', { method: 'HEAD' });
  expect(response.ok).not.toBe(true);
});

Dependencies (4)

Dev Dependencies (0)

    Package Sidebar

    Install

    npm i @jomaxx/jest-polly

    Weekly Downloads

    3

    Version

    2.1.0

    License

    MIT

    Unpacked Size

    3.36 kB

    Total Files

    6

    Last publish

    Collaborators

    • jomaxx