javascript - sinon.js fake server responses -


i created fake server , 2 things in end:

  • answer request
  • check passed data

this works way:

    server.respondwith("post", serveruri, [ 200, {"content-type": "application/text"}, "answer fake server" ]); // f1     server.respondwith(function(data) { // f2             try {                 var datasenttoserver = data.requestbody;                 ok(datatoregister === datasenttoserver, testcomment);             } catch (e) {                 console.error(e);             }         }     ); 

but @ beginning of test don't want response. leave f1 away. after statements want server call f1 , f2. adding line of f1 doesn't work because f2 not called more. seems f1 overwrites f2. need redeclare f2 well.

is there possibility add behaviour existing respondwith() functions?

it's similar task of fake-server test. must leave 1 function respondwith , write inside logic of data , answers of server.

   server.respondwith(method, model,      (function() {        var answer = [];        if (model.attributes.car_model == "") {         answer = [           404,           { "content-type": "application/json" },           '[{"0":"not car selected"}]'         ];       } else {         answer = [           200,           { "content-type": "application/json" },           '[{"0":"good query"}]'         ];       }        return answer;      })(model)); 

where 'model' - data ajax, in if-else blocks verify data , sent necessary answer browser.


Comments

Popular posts from this blog

java - Intellij Synchronizing output directories .. -

git - Initial Commit: "fatal: could not create leading directories of ..." -