diff --git a/superagent/superagent-tests.ts b/superagent/superagent-tests.ts index 237cbdeda1c2b8..283244ac85e641 100644 --- a/superagent/superagent-tests.ts +++ b/superagent/superagent-tests.ts @@ -5,6 +5,7 @@ import * as request from 'superagent'; import * as fs from 'fs'; +import * as assert from 'assert'; // Examples taken from https://github.com/visionmedia/superagent/blob/gh-pages/docs/index.md // and https://github.com/visionmedia/superagent/blob/master/Readme.md @@ -302,4 +303,14 @@ request request .get('/search') .then((response) => {}) - .catch((error) => {}); \ No newline at end of file + .catch((error) => {}); + +// Requesting binary data. +// adapted from: https://github.com/visionmedia/superagent/blob/v2.0.0/test/client/request.js#L110 +request + .get('/blob') + .responseType('blob') + .end(function (err, res) { + assert(res.xhr instanceof XMLHttpRequest) + assert(res.xhr.response instanceof Blob); + }); diff --git a/superagent/superagent.d.ts b/superagent/superagent.d.ts index 1d89adeb6ba9c8..c41847775c4bfa 100644 --- a/superagent/superagent.d.ts +++ b/superagent/superagent.d.ts @@ -77,6 +77,7 @@ declare module "superagent" { notAcceptable: boolean; notFound: boolean; forbidden: boolean; + xhr: XMLHttpRequest; get(header: string): string; } @@ -96,6 +97,7 @@ declare module "superagent" { pipe(stream: NodeJS.WritableStream, options?: Object): stream.Writable; query(val: Object): this; redirects(n: number): this; + responseType(type: string): this; send(data: string): this; send(data: Object): this; send(): this;