TypeError: $ browser.cookies is not a function

EDIT: I solved the problem by lowering angular -mocks to 1.3.x (I am using AngularJS 1.3.x)


I am learning to write and run a test in my Angular app with karma and jasmine.

The first tests passed, but when implementing $httpBackend I received the following error:

 TypeError: $browser.cookies is not a function at sendReq (/typotheque-web/public/app/bower_components/angular/angular.js:9661:24) at serverRequest (/typotheque-web/public/app/bower_components/angular/angular.js:9383:16) at processQueue (/typotheque-web/public/app/bower_components/angular/angular.js:13248:27) at /typotheque-web/public/app/bower_components/angular/angular.js:13264:27 at Scope.$eval (/typotheque-web/public/app/bower_components/angular/angular.js:14466:28) at Scope.$digest (/typotheque-web/public/app/bower_components/angular/angular.js:14282:31) at Function.$httpBackend.flush (/typotheque-web/public/app/bower_components/angular-mocks/angular-mocks.js:1510:38) at Object.<anonymous> (/typotheque-web/public/test/libraryServiceSpec.js:74:17) 

The incriminated part of the code ...

 // ... var library, $httpBackend, BACKEND_URL; beforeEach(inject(function(_Library_, _$httpBackend_) { library = _Library_; $httpBackend = _$httpBackend_; BACKEND_URL = 'http://srvpartage.local:3000'; })); // ... describe('updateFonts()', function() { it('should request the fonts to the server', function() { var fonts; $httpBackend.expectGET(BACKEND_URL+'/fonts').respond(200, [{}, {}]); library.updateFonts(function(data) { fonts = data; }); $httpBackend.flush(); expect(fonts.length).toBeGreaterThan(0); }); }); 

And the updateFonts() method:

 this.updateFonts = function(callback) { return $http.get(BACKEND_URL+'/fonts') .success(function(data) { console.log('Library :: fonts updated', data); self.fonts = data; self.state.fonts.loaded = true; self.state.fonts.error = false; if(callback) callback(self.fonts); }).error(function() { self.state.fonts.error = true; }); }; 

When I delete this part, the tests pass fine. In any case, I referenced the angular-cookie library in my Karma configuration, but I still had an error.

I do not understand why I am getting this error, because I do not use cookies through the entire application .

+7
javascript angularjs cookies karma-runner jasmine
source share

No one has answered this question yet.

See similar questions:

nine
Get an error while trying to use jasmine and angular

or similar:

6493
var functionName = function () {} vs function functionName () {}
2644
Is there an "exists" function for jQuery?
2256
Set the default value for the JavaScript function
2
How to check the function in the injected controller?
one
Corner Service Checkout Timeout Using $ q and Corner Extended Promises
one
Mocha - TypeError: Cannot read property "$ scope" of undefined
one
Problem with TypeScript AngularJS controller with angular.mock.inject under karma + jasmine
0
Karma + Angular1: window.angular. $$ csp is not a function
0
$ scope. $ apply undefined angularJS unit testing jasmine
0
injection during use gives errors during angular testing

All Articles