11/* tslint:disable:no-unused-variable */
22import TKUnit = require( "./TKUnit" ) ;
3- import fetchModule = require( "fetch" ) ;
43import types = require( "utils/types" ) ;
54
65// <snippet module="fetch" title="fetch">
@@ -12,18 +11,18 @@ import types = require("utils/types");
1211// </snippet>
1312
1413export var test_fetch_defined = function ( ) {
15- TKUnit . assert ( types . isDefined ( ( fetchModule . fetch ) ) , "Method fetch() should be defined!" ) ;
14+ TKUnit . assert ( types . isDefined ( ( fetch ) ) , "Method fetch() should be defined!" ) ;
1615} ;
1716
1817export var test_fetch = function ( done : ( err : Error , res ?: string ) => void ) {
1918 var result ;
2019 // <snippet module="fetch" title="fetch">
2120 // ### Get Response from URL
2221 // ``` JavaScript
23- fetchModule . fetch ( "https://httpbin.org/get" ) . then ( function ( r ) {
22+ fetch ( "https://httpbin.org/get" ) . then ( function ( r ) {
2423 //// Argument (r) is Response!
2524 // <hide>
26- TKUnit . assert ( r instanceof fetchModule . Response , "Result from fetch() should be valid Response object! Actual result is: " + result ) ;
25+ TKUnit . assert ( r instanceof Response , "Result from fetch() should be valid Response object! Actual result is: " + result ) ;
2726 done ( null ) ;
2827 // </hide>
2928 } , function ( e ) {
@@ -42,7 +41,7 @@ export var test_fetch_text = function (done: (err: Error, res?: string) => void)
4241 // <snippet module="fetch" title="fetch">
4342 // ### Get string from URL
4443 // ``` JavaScript
45- fetchModule . fetch ( "https://httpbin.org/get" ) . then ( response => { return response . text ( ) ; } ) . then ( function ( r ) {
44+ fetch ( "https://httpbin.org/get" ) . then ( response => { return response . text ( ) ; } ) . then ( function ( r ) {
4645 //// Argument (r) is string!
4746 // <hide>
4847 TKUnit . assert ( types . isString ( r ) , "Result from text() should be string! Actual result is: " + r ) ;
@@ -64,7 +63,7 @@ export var test_fetch_json = function (done: (err: Error, res?: string) => void)
6463 // <snippet module="fetch" title="fetch">
6564 // ### Get JSON from URL
6665 // ``` JavaScript
67- fetchModule . fetch ( "https://httpbin.org/get" ) . then ( response => { return response . json ( ) ; } ) . then ( function ( r ) {
66+ fetch ( "https://httpbin.org/get" ) . then ( response => { return response . json ( ) ; } ) . then ( function ( r ) {
6867 //// Argument (r) is JSON object!
6968 // <hide>
7069 TKUnit . assert ( types . isString ( JSON . stringify ( r ) ) , "Result from json() should be JSON object! Actual result is: " + r ) ;
@@ -86,7 +85,7 @@ export var test_fetch_blob = function (done: (err: Error, res?: string) => void)
8685 // <snippet module="fetch" title="fetch">
8786 // ### Get Blob from URL
8887 // ``` JavaScript
89- fetchModule. fetch("https://httpbin.org/get").then(response => { return response.blob(); }).then(function (r) {
88+ fetch("https://httpbin.org/get").then(response => { return response.blob(); }).then(function (r) {
9089 //// Argument (r) is Blob object!
9190 // <hide>
9291 TKUnit.assert(r instanceof Blob, "Result from blob() should be Blob object! Actual result is: " + r);
@@ -108,7 +107,7 @@ export var test_fetch_arrayBuffer = function (done: (err: Error, res?: string) =
108107 // <snippet module="fetch" title="fetch">
109108 // ### Get ArrayBuffer from URL
110109 // ``` JavaScript
111- fetchModule. fetch("https://httpbin.org/get").then(response => { return response.arrayBuffer(); }).then(function (r) {
110+ fetch("https://httpbin.org/get").then(response => { return response.arrayBuffer(); }).then(function (r) {
112111 //// Argument (r) is ArrayBuffer object!
113112 // <hide>
114113 TKUnit.assert(r instanceof ArrayBuffer, "Result from arrayBuffer() should be ArrayBuffer object! Actual result is: " + r);
@@ -131,7 +130,7 @@ export var test_fetch_formData = function (done: (err: Error, res?: string) => v
131130 // <snippet module="fetch" title="fetch">
132131 // ### Get FormData from URL
133132 // ``` JavaScript
134- fetchModule . fetch ( "https://httpbin.org/get" ) . then ( response => { return response . formData ( ) ; } ) . then ( function ( r ) {
133+ fetch ( "https://httpbin.org/get" ) . then ( response => { return response . formData ( ) ; } ) . then ( function ( r ) {
135134 //// Argument (r) is FormData object!
136135 // <hide>
137136 TKUnit . assert ( r instanceof FormData , "Result from formData() should be FormData object! Actual result is: " + r ) ;
@@ -151,7 +150,7 @@ export var test_fetch_fail_invalid_url = function (done) {
151150 var completed : boolean ;
152151 var isReady = function ( ) { return completed ; }
153152
154- fetchModule . fetch ( "hgfttp://httpbin.org/get" ) . catch ( function ( e ) {
153+ fetch ( "hgfttp://httpbin.org/get" ) . catch ( function ( e ) {
155154 completed = true ;
156155 done ( null )
157156 } ) ;
@@ -162,7 +161,7 @@ export var test_fetch_response_status = function (done) {
162161 // <snippet module="fetch" title="fetch">
163162 // ### Get Response status
164163 // ``` fetch
165- fetchModule . fetch ( "https://httpbin.org/get" ) . then ( function ( response ) {
164+ fetch ( "https://httpbin.org/get" ) . then ( function ( response ) {
166165 //// Argument (response) is Response!
167166 var statusCode = response . status ;
168167 // <hide>
@@ -189,7 +188,7 @@ export var test_fetch_response_headers = function (done) {
189188 // <snippet module="fetch" title="fetch">
190189 // ### Get response headers
191190 // ``` JavaScript
192- fetchModule . fetch ( "https://httpbin.org/get" ) . then ( function ( response ) {
191+ fetch ( "https://httpbin.org/get" ) . then ( function ( response ) {
193192 //// Argument (response) is Response!
194193 // var all = response.headers.getAll();
195194 // <hide>
@@ -212,9 +211,9 @@ export var test_fetch_response_headers = function (done) {
212211} ;
213212
214213export var test_fetch_headers_sent = function ( done ) {
215- var result : fetchModule . Headers ;
214+ var result : Headers ;
216215
217- fetchModule . fetch ( "https://httpbin.org/get" , {
216+ fetch ( "https://httpbin.org/get" , {
218217 method : "GET" ,
219218 headers : { "Content-Type" : "application/json" }
220219 } ) . then ( function ( response ) {
@@ -236,7 +235,7 @@ export var test_fetch_post_form_data = function (done) {
236235 data . append ( "MyVariableOne" , "ValueOne" ) ;
237236 data . append ( "MyVariableTwo" , "ValueTwo" ) ;
238237
239- fetchModule . fetch ( "https://httpbin.org/post" , {
238+ fetch ( "https://httpbin.org/post" , {
240239 method : "POST" ,
241240 headers : { "Content-Type" : "application/x-www-form-urlencoded" } ,
242241 body : data
@@ -259,7 +258,7 @@ export var test_fetch_post_json = function (done) {
259258 // <snippet module="fetch" title="fetch">
260259 // ### Post JSON
261260 // ``` JavaScript
262- fetchModule . fetch ( "https://httpbin.org/post" , {
261+ fetch ( "https://httpbin.org/post" , {
263262 method : "POST" ,
264263 headers : { "Content-Type" : "application/json" } ,
265264 body : JSON . stringify ( { MyVariableOne : "ValueOne" , MyVariableTwo : "ValueTwo" } )
0 commit comments