vendredi 26 août 2016

What is the difference between returning a Mirage.Response object vs returning a raw JSON object through Mirage?

I am trying to build an EmberJS test server in the browser. I have an API call to "myApiMethod", from which I am trying to GET a JSON object. While trying to test the response from a specific method I found out that that I can either return a raw json object, or wrap it in a Mirage.Response object. Since I wanted the mock server's response to be reflective of the real world, I wasn't sure which of the two was a better idea.

What I wanted to know was the functional differences between the following two chunks of code that I have in my Mirage's config.js:

Version 1:

    this.get('/myApiMethod', function(param1, param2){
        var jsonObject = myFunctionThatReturnsJson(param1, param2);
        return jsonObject;
    });

vs.

Version 2:

    this.get('/myApiMethod',function(param1, param2){
        var jsonObject = myFunctionThatReturnsJson(param1, param2);
        return Mirage.Response(200, {}, jsonObject); 
    });




Aucun commentaire:

Enregistrer un commentaire