I'm unit testing an Angular controller that uses a Rails Resource factory to handle GETing and POSTing model data from and to a Rails app. POSTing is done via a method on the model, e.g. (with a model $scope.resource
):
$scope.resource.update().then(successHandler, failureHandler);
I have a spy on this method to stub out the Ajax calls so I can unit test the controller:
resUpdateSpy = spyOn($scope.resource, 'update').and.callFake(function() {
return {then: function(success, failure){ success(resUpdateResponse); }};
});
In one of my controller methods, I expect the resource to be POSTed with certain data (Stripe data in particular). The data will be overridden after the POST in the same method, so I cannot test the state of the model afterwards. Ideally, I would like to something like:
expect($scope.resource.update).toHaveBeenCalled().whileValueOf($scope.resource.stripeKey).isEqualTo('tok123');
Obviously, this method doesn't exist in vanilla Jasmine. Is there a way in Jasmine (either vanilla or through a third-party project) to test the state of a value when a given spy is called? or is there another way to test this situation – specifically, the state of a model before its data POSTs – that I'm missing?
I'm running Jasmine 2.2.0 with Teaspoon 1.0.2 on an Angular 1.3.14 app.