Sto provando a eseguire alcuni test con jasmine per un servizio AngularJS che ho creato per Spotify. Ma continuo a ricevere un errore con i miei test quando testare le promesse.
Il mio test è attualmente in questo modo:
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(); //This line causes the error
});
});
e l'errore che viene fuori è:
✗ 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
linea 249 è $ httpBackend.flush()
sto usando karma-gelsomino e test di corsa attraverso PhantomJS.
- AngularJS: 1.2.24
- angolari-deride: 1.2.16
- angolare scenario: 1.2.16
- karma-gelsomino: 0.2.0
Perché sarebbe $ httpBackend sta provando a cambiare l'URL nel browser?
Qualsiasi aiuto su questo sarebbe fantastico.
Hai ragione haha. Era solo un missmatch di versione tra danze angolari e angolari. –
ottima risposta! Grazie. – Rocco