4

I am writing Unit Test Case In javascript using qunit. i am calling one URL using ajax call and using GET method but it is not calling URL. I am Providing Test below:

 QUnit.test( "Importing Grid", function(assert) {
    var done = assert.async();    
    var data = {
        "info": {"view":"LATEST","mode": 1,"memberId": 1001,"baselineId": -1}
    }
    console.log(cuboid_id+" : "+cuboid_name);
    $.ajax({
        url: Globals.baseURL + "rest/grid/"+cuboid_id,
        type: "GET",
        dataType: "application/json",
        data: JSON.stringify(data),
        contentType: "application/json",
        success: function(result){                
            console.log(JSON.stringify(result));                                                       
            assert.equal(result !=null,true,"Response should not be null");               
            assert.equal(result[0].error,"Whitebaord ID NOT FOUND","InValid Whiteboard ID");               
            done();
        }
    });
});

Can someone suggest me what to change in ajax Call?? I tried this stackoverflow answer but it is not working Thanks In Advance.

Mosè Raguzzini
  • 12,776
  • 26
  • 36
Jaydeep Bobade
  • 895
  • 9
  • 20

1 Answers1

1

try this

$.ajax({
    url: Globals.baseURL + "rest/grid/"+cuboid_id,
    type: "GET",
    dataType: "application/json",
    data: {some_query_var : JSON.stringify(data)},
    contentType: "application/json",
    success: function(result){
        console.log("***********************++++++++++++++*************************");
        console.log(JSON.stringify(result));                                                       
        //assert.equal(result !=null,true,"Response should not be null");               
        //assert.equal(result[0].error,"Whitebaord ID NOT FOUND","InValid Whiteboard ID");
        assert.equal(1,1); 
        done();
    }
});

"dataType json" in ajax jquery doesn't mean for formating JSON string in "data" attribute .. you still need the query variable passing in the "data" attribute. wich is in this is case i use some_query_var.