I'm having a bit of trouble testing an AngularJS controller that is using Restangular to query an API. The test fails with TypeError: Cannot call method 'then' of undefined
which is in reference to the promise returned from Restangular.
I've reproduced the error in plunker here
I know I'm overlooking something small, but I can't figure out what it is?
Using AngularJS 1.2.5 and Restangular 1.2.0.
It looks like you are trying to resolve the promise again inside your test.
Since it's already been then()
'd in the controller, you just need to set it to the variable you set in the callback:
resolvedValue = $scope.disaggregators;
instead of doing then()
again.
See updated plunkr here
note: I hard set the response to match since the api call doesn't work