i have examplemodel calls exampleservice retrieves data our backend. can't figure out how write unit tests application; structured shown below:
exampleservice
public function retrievemytodolist(parameters):promise { var promise:promise = performrequest({request: "call backend", parameters: values, session_id: clientmodel.sessionid}); promise.addresultprocessor(parseretrievetodolistresult); return promise; } protected function parseretrievetodolistresult(data:object, callback:function):void { json parsing object callback(null, object containing retrieved data) }
examplemodel
public function getmytodolist():promise { var promise:promise = exampleservice.retrievetodolist(parameters); promise.addresulthandler(ongettodolistresult); promise.adderrorhandler(ongettodolisterror); return promise; } private function ongetheadrsbyuserresult(promise:promise):void { // event listened mediators etc dispatchevent(new responseevent(good_result)); } private function ongetheadrsbyusererror(promise:promise):void { dispatchevent(new responseevent(bad_result)); }
i'm trying use asmock mock service can test model , how handles various results in resulting object how mock callback? saw examples return values mocked in case i'm using promise , callback , i'm not sure how go ahead.
if please advise. thanks!
you can let mock service return real promise , call handleresult
method of promise directly.
fyi: it's not idea have direct dependency model service. should let service manipulate model, or pass results service command manipulate model. models should never depend on else helper classes.
Comments
Post a Comment