Record and playback http requests from your Jest tests
Clone or download
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
src fix: compute hash correctly for records with JSON body (#351) Nov 30, 2018
tests
.editorconfig
.gitattributes
.gitignore feat: initial commit Jul 12, 2017
.npmignore feat: initial commit Jul 12, 2017
.travis.yml chore(deps): Update dependency tslint-config-ikatyang to version 2.x (#… Jul 30, 2017
CHANGELOG.md chore(release): 2.0.2 Nov 30, 2018
LICENSE
README.md
jest.config.js fix(play): disable allowUnmocked (#328) Sep 21, 2018
package.json chore(deps): update dependency prettier to v1.16.1 Jan 23, 2019
prettier.config.js chore: update tslint config Nov 4, 2017
renovate.json chore: update renovate.json Aug 20, 2017
tsconfig.build.json feat: initial commit Jul 12, 2017
tsconfig.json
tslint.json fix(play): disable allowUnmocked (#328) Sep 21, 2018
yarn.lock

README.md

jest-playback

npm build

Record and playback http requests from your Jest tests

Changelog

Install

# using npm
npm install --save-dev jest-playback jest

# using yarn
yarn add --dev jest-playback jest

Usage

// records are stored in `${__dirname}/__playbacks__`.
require("jest-playback").setup(__dirname);

const request = require("request");

test("example", done => {
  request('http://www.example.com/', (_err, _res, body) => {
    expect(body).toMatchSnapshot();
    done();
  });
});

You can control which mode to use by specifying the second argument of setup:

require("jest-playback").setup(__dirname, "record");

or via the JEST_PLAYBACK_MODE environment variable:

JEST_PLAYBACK_MODE=record npx jest

Modes

  • run (default)

    • play records
    • enable net connet
  • play

    • play records
    • disable net connet
  • record

    • enable net connect
    • record all requests
  • real

    • enable net connect

Development

# lint
yarn run lint

# build
yarn run build

# test
yarn run test

Related

  • nock: HTTP mocking and expectations library
  • ava-playback: Record and playback http requests from your ava tests

License

MIT © Ika