test/unit/angularjs/rails/interceptorsSpec.js in angularjs-rails-resource-1.2.0 vs test/unit/angularjs/rails/interceptorsSpec.js in angularjs-rails-resource-1.2.1
- old
+ new
@@ -210,9 +210,30 @@
expect(interceptorCalled).toBeTruthy();
});
});
+ describe('beforeResponse', function() {
+ it('should run interceptor only once', function() {
+ var Resource, interceptorCalledCount = 0;
+
+ $httpBackend.expectGET('/test/123').respond(200, {id: 123, abc_def: 'xyz'});
+
+ Resource = factory(config);
+ Resource.addInterceptor({
+ 'beforeResponse': function (response, constructor, context) {
+ interceptorCalledCount++;
+ return response;
+ }
+ });
+
+ Resource.get(123)
+ $httpBackend.flush();
+
+ expect(interceptorCalledCount).toEqual(1);
+ });
+ });
+
describe('response', function () {
it('should be able to reference interceptor using name', function () {
var promise, result, Resource, testConfig = {};
$httpBackend.expectGET('/test/123').respond(200, {id: 123, abc_def: 'xyz'});