Skip to content

Commit 6cd62bb

Browse files
author
Vladimir Enchev
committed
tests improved
1 parent fd32979 commit 6cd62bb

File tree

1 file changed

+17
-9
lines changed

1 file changed

+17
-9
lines changed

apps/tests/fetch-tests.ts

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,23 @@ export var test_fetch_defined = function () {
1717

1818
export var test_fetch = function (done: (err: Error, res?: string) => void) {
1919
var result;
20-
20+
// <snippet module="fetch" title="fetch">
21+
// ### Get Response from URL
22+
// ``` JavaScript
2123
fetchModule.fetch("https://httpbin.org/get").then(function (r) {
24+
//// Argument (r) is Response!
25+
// <hide>
2226
TKUnit.assert(r instanceof fetchModule.Response, "Result from fetch() should be valid Response object! Actual result is: " + result);
2327
done(null);
28+
// </hide>
2429
}, function (e) {
30+
//// Argument (e) is Error!
31+
// <hide>
2532
done(e);
33+
// </hide>
2634
});
35+
// ```
36+
// </snippet>
2737
};
2838

2939
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)
3242
// <snippet module="fetch" title="fetch">
3343
// ### Get string from URL
3444
// ``` 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) {
3646
//// Argument (r) is string!
3747
// <hide>
3848
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)
5464
// <snippet module="fetch" title="fetch">
5565
// ### Get JSON from URL
5666
// ``` 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) {
5868
//// Argument (r) is JSON object!
5969
// <hide>
6070
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)
7686
// <snippet module="fetch" title="fetch">
7787
// ### Get Blob from URL
7888
// ``` 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) {
8090
//// Argument (r) is Blob object!
8191
// <hide>
8292
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) =
98108
// <snippet module="fetch" title="fetch">
99109
// ### Get ArrayBuffer from URL
100110
// ``` 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) {
102112
//// Argument (r) is ArrayBuffer object!
103113
// <hide>
104114
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
120130
// <snippet module="fetch" title="fetch">
121131
// ### Get FormData from URL
122132
// ``` 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) {
124134
//// Argument (r) is FormData object!
125135
// <hide>
126136
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
137147
};
138148
*/
139149
export var test_fetch_fail_invalid_url = function (done) {
140-
var result;
141150
var completed: boolean;
142151
var isReady = function () { return completed; }
143152

144153
fetchModule.fetch("hgfttp://httpbin.org/get").catch(function (e) {
145154
completed = true;
146-
result = e;
147155
done(null)
148156
});
149157
};
150158

151159
export var test_fetch_response_status = function (done) {
152160

153161
// <snippet module="fetch" title="fetch">
154-
// ### Get response status code
162+
// ### Get Response status
155163
// ``` fetch
156164
fetchModule.fetch("https://httpbin.org/get").then(function (response) {
157165
//// Argument (response) is Response!

0 commit comments

Comments
 (0)