Skip to content

Commit

Permalink
fix(adapter-fetch): Handle Request objects as URLs (#220)
Browse files Browse the repository at this point in the history
  • Loading branch information
tombh authored and offirgolan committed Jul 17, 2019
1 parent 82b45dd commit bb28d54
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
5 changes: 5 additions & 0 deletions packages/@pollyjs/adapter-fetch/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ export default class FetchAdapter extends Adapter {
this.native = context.fetch;

context.fetch = async (url, options = {}) => {
// Support Request object
if (typeof url === 'object' && 'url' in url) {
url = url.url;
}

const pollyRequest = await this.handleRequest({
url,
method: options.method || 'GET',
Expand Down
10 changes: 10 additions & 0 deletions packages/@pollyjs/adapter-fetch/tests/integration/adapter-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,16 @@ describe('Integration | Fetch Adapter', function() {
expect(res.status).to.equal(200);
});

it('should support Request objects', async function() {
const { server } = this.polly;

server.any(this.recordUrl()).intercept((_, res) => res.sendStatus(200));

const res = await this.fetch(new Request(this.recordUrl()));

expect(res.status).to.equal(200);
});

it('should support array of key/value pair headers', async function() {
const { server } = this.polly;
let headers;
Expand Down

0 comments on commit bb28d54

Please sign in to comment.