Unit testing AngularJS with $httpBackend gives “Error: Unexpected Request”

纵饮孤独 提交于 2019-12-01 17:03:58

My first thought is that something is making a request when you instantiate your controller. Maybe try adding the $httpBackend.flush() after your controller declaration line and see if that solves it. Also, should your $scope.$digest be after the $httpBackend.flush instead of before?

I found out what it was. my register_user() function was referencing $scope.user, which was being set to an undefined variable: userJohnDoeCredentials (a different variable name I had used for my previous test).

Not sure why my IDE wasn't complaining about me referencing an undefined variable, and it was passing all of my jslint tests, so that's strange too, but meh. It's fixed :D Only if now I could get the mock request to return what I want it to...

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!