You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I've been going at this for a while now and can't seem to figure out why it's not working or if it's even possible.
The framework being used is AngularJS.
Here's the test code:
describe('function login',()=>{it('should display toast notification when login fails',()=>{vm.username='';vm.password='';MockLoginService.setup(l=>l.login(It.isAnyString(),It.isAnyString())).returns(()=>Promise.reject({data: ''})asany);vm.login({});MockNotificationService.verify(n=>n.error(It.isAnyString()),Times.once());});});
Here's the method under test:
login($event: any){this.isLoading=true;this.LoginService.login(this.username,this.password).then(response=>{// removed unnecessary code here for issue},response=>{this.isLoading=false;if(response.data=='PasswordExpired'){this.NotificationService.error('Your password has expired.');this.forgotPassword($event,true);}else{this.NotificationService.error(`Failed to log in: ${response.data}`);}},()=>this.isLoading=false);}
The line that should be called (and that I know is being called during testing thanks to console statements) is this.NotificationService.error(Failed to log in: ${response.data});
Even though I'm 100% certain that the .error method is being called at runtime, the test runner is saying it never gets invoked. I believe that my test is written correctly, since if I copy that line and pull it out of the Promise block (e.g. at the top of the login function's body), the test passes.
Is it not possible in TypeMoq to verify that a mock's method was called within a Promise/lambda function?
Thanks for any help/clarity!
The text was updated successfully, but these errors were encountered:
I've been going at this for a while now and can't seem to figure out why it's not working or if it's even possible.
The framework being used is AngularJS.
Here's the test code:
Here's the method under test:
The line that should be called (and that I know is being called during testing thanks to console statements) is
this.NotificationService.error(
Failed to log in: ${response.data});
Even though I'm 100% certain that the
.error
method is being called at runtime, the test runner is saying it never gets invoked. I believe that my test is written correctly, since if I copy that line and pull it out of the Promise block (e.g. at the top of thelogin
function's body), the test passes.Is it not possible in TypeMoq to verify that a mock's method was called within a Promise/lambda function?
Thanks for any help/clarity!
The text was updated successfully, but these errors were encountered: