pollyjs
pollyjs copied to clipboard
docs: Extend TypeScript example
After using my original example (#440) a bit more in production, I've found it super handy to be able to pass in config overrides per test file.
Description
Now you can invoke the helper like so:
Example: Ignoring headers (API Keys)
const polly = autoSetupPolly({
matchRequestsBy: {
headers: { exclude: ['x-request-id', 'x-api-key'] },
}
});
Example: Ignoring generated data using a callback
const polly = autoSetupPolly({
matchRequestsBy: {
body(body, req) {
const json = JSON.parse(body);
delete json.uuid;
delete json.createdDate;
return JSON.stringify(json);
}
});
Motivation and Context
Sharing my improved code back upstream ❤️
Types of Changes
- [x] New feature (non-breaking change which adds functionality)
Checklist
- [x] I have added tests to cover my changes.
- [x] My change requires a change to the documentation.
- [x] I have updated the documentation accordingly.
- [x] My code follows the code style of this project.
- [x] My commits and the title of this PR follow the Conventional Commits Specification.
- [x] I have read the contributing guidelines.