test.js

function assert(value,desc) {
    
    var li = document.createElement("li");
    li.className = value ? "pass" : "fail";
    li.appendChild(document.createTextNode(desc));
    document.getElementById("results").appendChild(li);

}


function pass(desc) {
    
    var li = document.createElement("li");
    li.className = "pass";
    li.appendChild(document.createTextNode(desc));
    document.getElementById("results").appendChild(li);

}



function  fail(desc) {

    var li = document.createElement("li");
    li.className = "fail";
    li.appendChild(document.createTextNode(desc));
    document.getElementById("results").appendChild(li);


}



function report(text) {

    assert(true,text);
}



function getJSON(url){

    return new Promise((resolve,reject)=>{
        const request = new XMLHttpRequest();
        request.open("GET",url);

        request.onload = function() {

            try{
                
                if (this.status ===200) {
                    resolve(JSON.parse(this.response));

                } else {

                    reject(this.status + " " + this.statusText);
                }

            } catch (en) {

                reject(en.message);

            }

        }


        request.onerror = function() {
            reject(this.status + " " + this.statusText);
        }


        request.send();

    });

}
posted @ 2020-12-02 11:55  yongjar  阅读(139)  评论(0编辑  收藏  举报