Commit 101fd0ba authored by Romain Courteaud's avatar Romain Courteaud

[test] Make it more readable by using promise

parent b53e74be
...@@ -17,15 +17,15 @@ ...@@ -17,15 +17,15 @@
* See COPYING file for full licensing terms. * See COPYING file for full licensing terms.
* See https://www.nexedi.com/licensing for rationale and options. * See https://www.nexedi.com/licensing for rationale and options.
*/ */
/*global setTimeout*/ (function (jIO, QUnit) {
(function (jIO, QUnit, setTimeout) {
"use strict"; "use strict";
var test = QUnit.test, var test = QUnit.test,
equal = QUnit.equal, equal = QUnit.equal,
stop = QUnit.stop, stop = QUnit.stop,
start = QUnit.start, start = QUnit.start,
expect = QUnit.expect, expect = QUnit.expect,
module = QUnit.module; module = QUnit.module,
ok = QUnit.ok;
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// util.stringify // util.stringify
...@@ -55,44 +55,29 @@ ...@@ -55,44 +55,29 @@
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
// util.ajax // util.ajax
///////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////
module("util.ajax", { module("util.ajax");
setup: function () {
var context = this;
this.jioerror = jIO.util.jIOError;
this.error_spy = {};
function fakejIOError(message, status_code) {
context.error_spy.message = message;
context.error_spy.status_code = status_code;
}
fakejIOError.prototype = new Error();
fakejIOError.prototype.constructor = fakejIOError;
jIO.util.jIOError = fakejIOError;
},
teardown: function () {
jIO.util.jIOError = this.jioerror;
}
});
test("ajax timeout", function () { test("ajax timeout", function () {
var timeout = 1, var timeout = 1;
context = this;
stop(); stop();
expect(2); expect(3);
jIO.util.ajax({ return new RSVP.Queue()
.then(function () {
return jIO.util.ajax({
type: 'GET', type: 'GET',
url: "//www.foo/com/bar", url: "https://www.example.org/com/bar",
timeout: timeout timeout: timeout
}); });
})
setTimeout(function () { .fail(function (error) {
ok(error instanceof jIO.util.jIOError);
equal(error.message, "Gateway Timeout");
equal(error.status_code, 504);
})
.always(function () {
start(); start();
equal(context.error_spy.message, "Gateway Timeout");
equal(context.error_spy.status_code, 504);
}, 10);
}); });
}(jIO, QUnit, setTimeout)); });
\ No newline at end of file }(jIO, QUnit));
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment