Record and playback HTTP requests from your Jest tests
npm install jest-playback

Record and playback HTTP requests from your Jest tests
``sh`
npm install jest-playback
`js
import * as jestPlayback from 'jest-playback'
await jestPlayback.setup()
test('example', async () => {
const response = await fetch('http://www.example.com/')
expect(response.status).toBe(200)
})
`
The records are stored as snapshots.
`ts
export default setup
export declare function setup(options?: Options): Promise
export interface Options {
/* @default Mode.Auto /
mode?: Mode
getRequestCacheKey?: (request: Request) => string | Promise
}
export enum Mode {
/**
* - Mode.Update if Jest --update-snapshot flag specifiedMode.Play
* - if Jest --ci flag specifiedMode.Record
* - otherwise`
*/
Auto = 'auto',
/**
* - all requests are recorded
*/
Update = 'update',
/**
* - play records
* - new requests are blocked
*/
Play = 'play',
/**
* - play records
* - new requests are recorded
*/
Record = 'record',
}
`shlint
pnpm run lint
MIT © Ika