Skip to content

Commit

Permalink
[TIMOB-20367] Add test case
Browse files Browse the repository at this point in the history
  • Loading branch information
Gary Mathews committed May 16, 2018
1 parent 9b03dbe commit e8b3b69
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions tests/Resources/ti.network.httpclient.addontest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* Appcelerator Titanium Mobile
* Copyright (c) 2011-Present by Appcelerator, Inc. All Rights Reserved.
* Licensed under the terms of the Apache Public License
* Please see the LICENSE included with this distribution for details.
*/
/* eslint-env mocha */
/* global Ti */
/* eslint no-unused-expressions: "off" */
'use strict';
var should = require('./utilities/assertions');

describe('Titanium.Network.HTTPClient', function () {
this.timeout(6e4);

it.android('save response data to temp directory', function (finish) {
var xhr = Ti.Network.createHTTPClient(),
attempts = 3;
xhr.setTimeout(6e4);

xhr.onload = function (e) {
try {
should(e.source.responseData.nativePath).be.a.string;
if (e.source.responseData.nativePath.includes('cache/_tmp') !== -1) {
finish();
} else {
finish(new Error('not saving response data to temp directory'));
}
} catch (err) {
finish(err);
}
};
xhr.onerror = function (e) {
if (attempts-- > 0) {
Ti.API.warn('failed, attempting to retry request...');
xhr.send();
} else {
Ti.API.debug(JSON.stringify(e, null, 2));
finish(new Error('failed to authenticate: ' + e));
}
};

xhr.open('GET', 'https://www.nasa.gov/sites/default/files/thumbnails/image/sun_0.jpg');
xhr.send();
});
});

0 comments on commit e8b3b69

Please sign in to comment.