Tôi đang cố gắng thực hiện một số thử nghiệm với hoa nhài cho một dịch vụ AngularJS mà tôi đã tạo cho Spotify. Nhưng tôi vẫn gặp lỗi với các bài kiểm tra của mình khi thử nghiệm lời hứa.
thử nghiệm của tôi hiện nay là như thế này:
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
});
});
và lỗi mà đi ra là:
✗ 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
Đường dây 249 là $ httpBackend.flush()
Tôi đang sử dụng nghiệp hoa nhài và chạy thử nghiệm thông qua PhantomJS.
- AngularJS: 1.2.24
- góc-mocks: 1.2.16
- góc-kịch bản: 1.2.16
- nghiệp-hoa nhài: 0.2.0
Tại sao $ httpBackend đang cố gắng thay đổi url trong trình duyệt?
Bất kỳ trợ giúp nào về điều này đều tuyệt vời.
Bạn đúng haha. Nó chỉ là một phiên bản missmatch giữa góc và góc-mocks. –
câu trả lời tuyệt vời! cảm ơn. – Rocco