Added tests for the promise() method on jqXHR

Ensures that the jqXHR object exposes a standard promise because it implements the JQueryPromise<T> interface.
This commit is contained in:
dan-def
2016-09-30 08:49:00 +01:00
committed by GitHub
parent c8a69b0b0c
commit 10940d2b42
+44
View File
@@ -209,6 +209,50 @@ function test_ajax() {
url: "test.js"
});
jqXHR.abort('aborting because I can');
//Test the promise exposed by the jqXHR object
// done method
$.ajax({
url: "test.js"
}).promise().done((data, textStatus, jqXHR) => {
console.log(data, textStatus, jqXHR);
});
// fail method
$.ajax({
url: "test.js"
}).promise().fail((jqXHR, textStatus, errorThrown) => {
console.log(jqXHR, textStatus, errorThrown);
});
// always method with successful request
$.ajax({
url: "test.js"
}).promise().always((data, textStatus, jqXHR) => {
console.log(data, textStatus, jqXHR);
});
// always method with failed request
$.ajax({
url: "test.js"
}).promise().always((jqXHR, textStatus, errorThrown) => {
console.log(jqXHR, textStatus, errorThrown);
});
// then method (as of 1.8)
$.ajax({
url: "test.js"
}).promise().then((data, textStatus, jqXHR) => {
console.log(data, textStatus, jqXHR);
}, (jqXHR, textStatus, errorThrown) => {
console.log(jqXHR, textStatus, errorThrown);
});
// generic then method
var p: JQueryPromise<number> = $.ajax({ url: "test.js" }).promise()
.then(() => "Hello")
.then((x) => x.length);
}
function test_ajaxComplete() {