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.

6
  • 2
    Possible duplicate of How to pass parameters in GET requests with jQuery Commented May 28, 2018 at 12:15
  • i tried that but it is not working Commented May 28, 2018 at 12:16
  • @HamzaAbdaoui here he is not passing parameters as key value pair but instead JSON object. Commented May 28, 2018 at 12:19
  • 1
    try removing dataType and data fields from ajax. if you want to send data in get, append those fields in url, or use post. Commented May 28, 2018 at 12:21
  • 1
    Request with GET/HEAD method cannot have body. This will create TypeError as it will fail to execute fetch on window. You should use query param in the url to send data. Commented May 29, 2018 at 9:44

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.