Record and playback http requests from your Jest tests
# using npm
npm install --save-dev jest-playback jest
# using yarn
yarn add --dev jest-playback jest// 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-
run(default)- play records
- enable net connet
-
play- play records
- disable net connet
-
record- enable net connect
- record all requests
-
real- enable net connect
# lint
yarn run lint
# build
yarn run build
# test
yarn run test- nock: HTTP mocking and expectations library
- ava-playback: Record and playback http requests from your ava tests
MIT © Ika