Describe (' forgot password:with username ', () ={let direlementinput; Beforeeach (()= { //Find The input control:Direlementinput = directiveelem.find (' input '); //Set some text!Angular.element (Direlementinput). Val (' [email protected] '). Trigger (' input '); $scope. $apply (); } ); It (' Should has username ', () ={expect (directiveCtrl.user.username). Toequal (' [Email protected] '); } ); It (' Should call userservice\ ' s Forgotpassword function ', () ={Spyon (UserService,' Forgotpassword '); Angular.element (Directiveelem.find (' button ') [2]). Click (); Expect (Userservice.forgotpassword). tohavebeencalled (); }); } ); Describe (' Forgot Password:without username ', () ={let direlementinput; Beforeeach (()={direlementinput= Directiveelem.find (' input '); Angular.element (Direlementinput). Val ("). Trigger (' input '); $scope. $apply (); }); It (' Should has empty username value ', () ={expect (directiveCtrl.user.username). tobeundefined (); }); It (' should not call userservice\ ' s Forgotpassword function ', () ={Spyon (UserService,' Forgotpassword '); Angular.element (Directiveelem.find (' button ') [2]). Click (); Expect (Userservice.forgotpassword). not.tohavebeencalled (); }) });
[Unit Testing] Based on input value, Spyon function