I am trying to do some jasmine testing for the AngularJS service that I created for Spotify. But when testing promises, I always get error messages.
My test currently looks like this:
describe('Spotify.search', function () { var $httpBackend; var $rootScope; var Spotify; var api = 'https://api.spotify.com/v1'; beforeEach(inject(function(_Spotify_, _$httpBackend_, _$rootScope_) { Spotify = _Spotify_; $httpBackend = _$httpBackend_; $rootScope = _$rootScope_; jasmine.getJSONFixtures().fixturesPath='base/test/mock'; })); it('should return an array of artists', function () { $httpBackend.when('GET', api + '/search?q=Nirvana&type=artist').respond( getJSONFixture('search.artist.json') ); Spotify.search('Nirvana', 'artist').then(function (data) { expect(data).toBeDefined(); expect(data.artists.items.length).toBeGreaterThan(0); }); $httpBackend.flush();
and the error that appears:
โ should return an array of artists TypeError: 'undefined' is not a function (evaluating '$browser.$$checkUrlChange()') at /Users/XXXX/Work/angular-spotify/bower_components/angular/angular.js:12502 at /Users/XXXX/Work/angular-spotify/bower_components/angular-mocks/angular-mocks.js:1438 at /Users/XXXX/Work/angular-spotify/test/spec/angular-spotify.spec.js:249
Line 249 - $ httpBackend.flush ()
I use karma jasmine and run tests through PhantomJS.
- AngularJS: 1.2.24
- angular -mocks: 1.2.16
- angular -scenario: 1.2.16
- karma jasmine: 0.2.0
Why is $ httpBackend trying to change the URL in the browser?
Any help on this would be great.
source share