@@ -17,13 +17,23 @@ export var test_fetch_defined = function () {
17
17
18
18
export var test_fetch = function ( done : ( err : Error , res ?: string ) => void ) {
19
19
var result ;
20
-
20
+ // <snippet module="fetch" title="fetch">
21
+ // ### Get Response from URL
22
+ // ``` JavaScript
21
23
fetchModule . fetch ( "https://httpbin.org/get" ) . then ( function ( r ) {
24
+ //// Argument (r) is Response!
25
+ // <hide>
22
26
TKUnit . assert ( r instanceof fetchModule . Response , "Result from fetch() should be valid Response object! Actual result is: " + result ) ;
23
27
done ( null ) ;
28
+ // </hide>
24
29
} , function ( e ) {
30
+ //// Argument (e) is Error!
31
+ // <hide>
25
32
done ( e ) ;
33
+ // </hide>
26
34
} ) ;
35
+ // ```
36
+ // </snippet>
27
37
} ;
28
38
29
39
export var test_fetch_text = function ( done : ( err : Error , res ?: string ) => void ) {
@@ -32,7 +42,7 @@ export var test_fetch_text = function (done: (err: Error, res?: string) => void)
32
42
// <snippet module="fetch" title="fetch">
33
43
// ### Get string from URL
34
44
// ``` JavaScript
35
- fetchModule . fetch ( "https://httpbin.org/get" ) . then ( r => { return r . text ( ) ; } ) . then ( function ( r ) {
45
+ fetchModule . fetch ( "https://httpbin.org/get" ) . then ( response => { return response . text ( ) ; } ) . then ( function ( r ) {
36
46
//// Argument (r) is string!
37
47
// <hide>
38
48
TKUnit . assert ( types . isString ( r ) , "Result from text() should be string! Actual result is: " + r ) ;
@@ -54,7 +64,7 @@ export var test_fetch_json = function (done: (err: Error, res?: string) => void)
54
64
// <snippet module="fetch" title="fetch">
55
65
// ### Get JSON from URL
56
66
// ``` JavaScript
57
- fetchModule . fetch ( "https://httpbin.org/get" ) . then ( r => { return r . json ( ) ; } ) . then ( function ( r ) {
67
+ fetchModule . fetch ( "https://httpbin.org/get" ) . then ( response => { return response . json ( ) ; } ) . then ( function ( r ) {
58
68
//// Argument (r) is JSON object!
59
69
// <hide>
60
70
TKUnit . assert ( types . isString ( JSON . stringify ( r ) ) , "Result from json() should be JSON object! Actual result is: " + r ) ;
@@ -76,7 +86,7 @@ export var test_fetch_blob = function (done: (err: Error, res?: string) => void)
76
86
// <snippet module="fetch" title="fetch">
77
87
// ### Get Blob from URL
78
88
// ``` JavaScript
79
- fetchModule.fetch("https://httpbin.org/get").then(r => { return r .blob(); }).then(function (r) {
89
+ fetchModule.fetch("https://httpbin.org/get").then(response => { return response .blob(); }).then(function (r) {
80
90
//// Argument (r) is Blob object!
81
91
// <hide>
82
92
TKUnit.assert(r instanceof Blob, "Result from blob() should be Blob object! Actual result is: " + r);
@@ -98,7 +108,7 @@ export var test_fetch_arrayBuffer = function (done: (err: Error, res?: string) =
98
108
// <snippet module="fetch" title="fetch">
99
109
// ### Get ArrayBuffer from URL
100
110
// ``` JavaScript
101
- fetchModule.fetch("https://httpbin.org/get").then(r => { return r .arrayBuffer(); }).then(function (r) {
111
+ fetchModule.fetch("https://httpbin.org/get").then(response => { return response .arrayBuffer(); }).then(function (r) {
102
112
//// Argument (r) is ArrayBuffer object!
103
113
// <hide>
104
114
TKUnit.assert(r instanceof ArrayBuffer, "Result from arrayBuffer() should be ArrayBuffer object! Actual result is: " + r);
@@ -120,7 +130,7 @@ export var test_fetch_formData = function (done: (err: Error, res?: string) => v
120
130
// <snippet module="fetch" title="fetch">
121
131
// ### Get FormData from URL
122
132
// ``` JavaScript
123
- fetchModule.fetch("https://httpbin.org/get").then(r => { return r .formData(); }).then(function (r) {
133
+ fetchModule.fetch("https://httpbin.org/get").then(response => { return response .formData(); }).then(function (r) {
124
134
//// Argument (r) is FormData object!
125
135
// <hide>
126
136
TKUnit.assert(r instanceof FormData, "Result from formData() should be FormData object! Actual result is: " + r);
@@ -137,21 +147,19 @@ export var test_fetch_formData = function (done: (err: Error, res?: string) => v
137
147
};
138
148
*/
139
149
export var test_fetch_fail_invalid_url = function ( done ) {
140
- var result ;
141
150
var completed : boolean ;
142
151
var isReady = function ( ) { return completed ; }
143
152
144
153
fetchModule . fetch ( "hgfttp://httpbin.org/get" ) . catch ( function ( e ) {
145
154
completed = true ;
146
- result = e ;
147
155
done ( null )
148
156
} ) ;
149
157
} ;
150
158
151
159
export var test_fetch_response_status = function ( done ) {
152
160
153
161
// <snippet module="fetch" title="fetch">
154
- // ### Get response status code
162
+ // ### Get Response status
155
163
// ``` fetch
156
164
fetchModule . fetch ( "https://httpbin.org/get" ) . then ( function ( response ) {
157
165
//// Argument (response) is Response!
0 commit comments