javascript - Method under test appearing in unit test other than in the action -


i wondering if give me pointers on designing unit tests, function being tested appears in test other in unit's action.

i'm writing server side javascript node , using rsvp asynchronous calls restful backend.

i structure unit tests follows.

//setup //action //assertion //cleanup 

right now, i'm building function asynchronously deletes enteries in database unit test looks this.

"deletingfunction_1entry_returns1entrydeleted": function() {       return new rsvp.promise(function( resolve, reject ) {       //setup       var databaseentry = { "info": "info" };       setup( databaseentry ).then(function( xpostedentries ) {       //if setup promise resolves then...           //action           xdelete( xpostedentries ).then(function( xdeletedenteries ) {               //assertion               if ( xpostedentries === xdeletedentries ) {               //if posted enteries matched deleted enteries then...                   resolve();               } else {               //otherwise posted enteries did not match deleted                 //enteries so...                   reject("the posted enteries did not match deleted enteries.");               }               });       }, function( xpostedenteries ) {       //otherwise setup promise did not resolve so...           //cleanup           /***************************************************************/           /* here's i'm having trouble. if setup fails post */           /* of entries database test       */                                         /* scratch want clean posts 'were'    */           /* posted remove them database, i'd using */           /* deleting function, function i'm testing.  */           /* how can redesign unit test not use function  */           /* it's testing.                                          */           /***************************************************************/           reject("the setup failed.");          }); }); 

}

edited: wrote function truncates database table clean still appreciate pointers on how improve testing.

this isn't unit test because has side-effects. of course can't use "delete" function you're testing. doesn't exist until passes unit tests. unit test needs unit test.

probably, want database connection dependency injected, abstract datastore. unit test use mock datastore.


Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -