mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-16 11:42:04 +08:00
tests improved
This commit is contained in:
@ -17,13 +17,23 @@ export var test_fetch_defined = function () {
|
||||
|
||||
export var test_fetch = function (done: (err: Error, res?: string) => void) {
|
||||
var result;
|
||||
|
||||
// <snippet module="fetch" title="fetch">
|
||||
// ### Get Response from URL
|
||||
// ``` JavaScript
|
||||
fetchModule.fetch("https://httpbin.org/get").then(function (r) {
|
||||
//// Argument (r) is Response!
|
||||
// <hide>
|
||||
TKUnit.assert(r instanceof fetchModule.Response, "Result from fetch() should be valid Response object! Actual result is: " + result);
|
||||
done(null);
|
||||
// </hide>
|
||||
}, function (e) {
|
||||
//// Argument (e) is Error!
|
||||
// <hide>
|
||||
done(e);
|
||||
// </hide>
|
||||
});
|
||||
// ```
|
||||
// </snippet>
|
||||
};
|
||||
|
||||
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)
|
||||
// <snippet module="fetch" title="fetch">
|
||||
// ### Get string from URL
|
||||
// ``` JavaScript
|
||||
fetchModule.fetch("https://httpbin.org/get").then(r => { return r.text(); }).then(function (r) {
|
||||
fetchModule.fetch("https://httpbin.org/get").then(response => { return response.text(); }).then(function (r) {
|
||||
//// Argument (r) is string!
|
||||
// <hide>
|
||||
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)
|
||||
// <snippet module="fetch" title="fetch">
|
||||
// ### Get JSON from URL
|
||||
// ``` JavaScript
|
||||
fetchModule.fetch("https://httpbin.org/get").then(r => { return r.json(); }).then(function (r) {
|
||||
fetchModule.fetch("https://httpbin.org/get").then(response => { return response.json(); }).then(function (r) {
|
||||
//// Argument (r) is JSON object!
|
||||
// <hide>
|
||||
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)
|
||||
// <snippet module="fetch" title="fetch">
|
||||
// ### Get Blob from URL
|
||||
// ``` JavaScript
|
||||
fetchModule.fetch("https://httpbin.org/get").then(r => { return r.blob(); }).then(function (r) {
|
||||
fetchModule.fetch("https://httpbin.org/get").then(response => { return response.blob(); }).then(function (r) {
|
||||
//// Argument (r) is Blob object!
|
||||
// <hide>
|
||||
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) =
|
||||
// <snippet module="fetch" title="fetch">
|
||||
// ### Get ArrayBuffer from URL
|
||||
// ``` JavaScript
|
||||
fetchModule.fetch("https://httpbin.org/get").then(r => { return r.arrayBuffer(); }).then(function (r) {
|
||||
fetchModule.fetch("https://httpbin.org/get").then(response => { return response.arrayBuffer(); }).then(function (r) {
|
||||
//// Argument (r) is ArrayBuffer object!
|
||||
// <hide>
|
||||
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
|
||||
// <snippet module="fetch" title="fetch">
|
||||
// ### Get FormData from URL
|
||||
// ``` JavaScript
|
||||
fetchModule.fetch("https://httpbin.org/get").then(r => { return r.formData(); }).then(function (r) {
|
||||
fetchModule.fetch("https://httpbin.org/get").then(response => { return response.formData(); }).then(function (r) {
|
||||
//// Argument (r) is FormData object!
|
||||
// <hide>
|
||||
TKUnit.assert(r instanceof FormData, "Result from formData() should be FormData object! Actual result is: " + r);
|
||||
@ -137,13 +147,11 @@ export var test_fetch_formData = function (done: (err: Error, res?: string) => v
|
||||
};
|
||||
*/
|
||||
export var test_fetch_fail_invalid_url = function (done) {
|
||||
var result;
|
||||
var completed: boolean;
|
||||
var isReady = function () { return completed; }
|
||||
|
||||
fetchModule.fetch("hgfttp://httpbin.org/get").catch(function (e) {
|
||||
completed = true;
|
||||
result = e;
|
||||
done(null)
|
||||
});
|
||||
};
|
||||
@ -151,7 +159,7 @@ export var test_fetch_fail_invalid_url = function (done) {
|
||||
export var test_fetch_response_status = function (done) {
|
||||
|
||||
// <snippet module="fetch" title="fetch">
|
||||
// ### Get response status code
|
||||
// ### Get Response status
|
||||
// ``` fetch
|
||||
fetchModule.fetch("https://httpbin.org/get").then(function (response) {
|
||||
//// Argument (response) is Response!
|
||||
|
Reference in New Issue
Block a user