Currently, I am unit testing an Angular controller that relies on a Rails Resource factory to manage data exchange with a Rails application. Specifically, POST requests are handled by calling a method on the model, like so:
$scope.resource.update().then(successHandler, failureHandler);
To facilitate unit testing of the controller, I have set up a spy on this method in order to simulate Ajax calls:
resUpdateSpy = spyOn($scope.resource, 'update').and.callFake(function() {
return {then: function(success, failure){ success(resUpdateResponse); }};
});
During testing, there is a need to ensure that certain data (such as Stripe information) is being POSTed with the resource. However, since the data is modified after the POST operation within the same method, traditional testing methods prove challenging. Ideally, I would like to validate the state of the resource during the POST using something like:
expect($scope.resource.update).toHaveBeenCalled().whileValueOf($scope.resource.stripeKey).isEqualTo('tok123');
Unfortunately, such a method is not available in standard Jasmine testing. Is there a way, possibly through vanilla Jasmine or a third-party extension, to examine the value of a property when a specific spy is triggered? Alternatively, is there another approach to testing this scenario – focusing on the state of the model prior to its data being sent out for POSTing?
My setup includes Jasmine 2.2.0 along with Teaspoon 1.0.2 integrated into an Angular 1.3.14 application.