node-fetch: introduce namespace _fetch for tests

This commit is contained in:
Torsten Werner
2016-06-07 22:51:25 +02:00
parent a6b828e148
commit 83c31efdd6
2 changed files with 11 additions and 8 deletions

View File

@@ -3,9 +3,9 @@
import fetch = require('node-fetch');
function test_fetchUrlWithOptions() {
var headers = new Headers();
var headers = new _fetch.Headers();
headers.append("Content-Type", "application/json");
var requestOptions: RequestInit = {
var requestOptions: _fetch.RequestInit = {
method: "POST",
headers: headers,
mode: 'same-origin',
@@ -17,7 +17,7 @@ function test_fetchUrlWithOptions() {
}
function test_fetchUrlWithHeadersObject() {
var requestOptions: RequestInit = {
var requestOptions: _fetch.RequestInit = {
method: "POST",
headers: {
'Content-Type': 'application/json'
@@ -31,13 +31,13 @@ function test_fetchUrl() {
}
function test_fetchUrlWithRequestObject() {
var requestOptions: RequestInit = {
var requestOptions: _fetch.RequestInit = {
method: "POST",
headers: {
'Content-Type': 'application/json'
}
};
var request: Request = new Request("http://www.andlabs.net/html5/uCOR.php", requestOptions);
var request: _fetch.Request = new _fetch.Request("http://www.andlabs.net/html5/uCOR.php", requestOptions);
handlePromise(fetch(request));
}
@@ -48,7 +48,7 @@ function test_globalFetchVar() {
});
}
function handlePromise(promise: Promise<Response>) {
function handlePromise(promise: Promise<_fetch.Response>) {
promise.then((response) => {
if (response.type === 'basic') {
// for test only

View File

@@ -3,7 +3,7 @@
// Definitions by: Torsten Werner <https://github.com/torstenwerner>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
declare module 'node-fetch' {
declare module _fetch {
class Request extends Body {
constructor(input: string | Request, init?: RequestInit);
@@ -88,5 +88,8 @@ declare module 'node-fetch' {
type RequestInfo = Request | string;
function fetch(url: string | Request, init?: RequestInit): Promise<Response>;
export = fetch;
}
declare module "node-fetch" {
export = _fetch.fetch;
}