rya*_*cey 7 javascript cookies jasmine angularjs karma-runner
编辑:我通过将角度模拟降级到1.3.x解决了这个问题(我使用的是AngularJS 1.3.x)
我正在学习使用Karma和Jasmine在我的Angular应用程序上编写和运行测试.
第一次测试通过,但实现时$httpBackend,我收到以下错误:
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)
Run Code Online (Sandbox Code Playgroud)
有罪的代码......
// ...
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);
});
});
Run Code Online (Sandbox Code Playgroud)
和updateFonts()方法:
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;
});
};
Run Code Online (Sandbox Code Playgroud)
当我删除这件作品时,测试运行正常.无论如何,我angular-cookie在我的Karma配置中引用了库,但我仍然遇到了错误.
我不明白为什么我会收到此错误,因为我没有在整个应用程序中使用cookie.
| 归档时间: |
|
| 查看次数: |
1705 次 |
| 最近记录: |