@jomaxx/jest-polly

2020-02-12

@jomaxx/jest-polly

An opinionated integration between Jest and Polly.js.

@jomaxx/jest-polly

An opinionated integration between Jestand 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 pollyinstance 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);
});

以上是 @jomaxx/jest-polly 的使用教程帮助文档。


上一篇:@spotify/polly-jest-presets
下一篇:@pollyjs/node-server
相关教程
关注微信

扫码加入 JavaScript 社区

相关文章
暂无相关文章

首次访问,需要验证
微信扫码,关注即可
(仅需验证一次)

欢迎加入 JavaScript 社区

号内回复关键字:

回到顶部