I am testing a module with an Angular controller that uses the Rails Resource factory to process GETing and POSTing model data from and to the Rails application. POSTing is done using a method on the model, for example. (with model $scope.resource):
$scope.resource.update().then(successHandler, failureHandler);
I have a spy on this method to drown out 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 (in particular, Stripe data). The data will be overridden after POST in the same method, so I canβt check the state of the model after that. Ideally, I would like something like:
expect($scope.resource.update).toHaveBeenCalled().whileValueOf($scope.resource.stripeKey).isEqualTo('tok123');
Obviously, this method does not exist in vanilla jasmine. Is there a way in Jasmine (or vanilla or through a third-party project) to check the status of the value when you call this spy? or is there another way to check this situation - in particular, the state of the model before its POST messages - what am I missing?
I am running Jasmine 2.2.0 with Teaspoon 1.0.2 in an Angular 1.3.14 application.
source
share