如何访问';配置';AngularJS中的拦截器对象
我正在测试一个角度拦截器。我想从jasmine单元测试的上下文中检查一些配置。下面是测试的代码如何访问';配置';AngularJS中的拦截器对象,angularjs,jasmine,karma-runner,Angularjs,Jasmine,Karma Runner,我正在测试一个角度拦截器。我想从jasmine单元测试的上下文中检查一些配置。下面是测试的代码 it('should set something on the config', function(){ $http.get('/myEndpoint'); $httpBackend.flush(); expect('????? -- I want to check the config.property here'); }); 这是生产代码 angular.module('a
it('should set something on the config', function(){
$http.get('/myEndpoint');
$httpBackend.flush();
expect('????? -- I want to check the config.property here');
});
这是生产代码
angular.module('app.core').factory('MyInterceptor', function MyInterceptor($injector) {
return {
request: function(config) {
config.property = 'check me in a test';
return config;
},
))
我的问题是如何从测试中检查配置属性?以下操作应该有效:
var config;
$httpBackend.expectGET('/myEndpoint').respond(200);
$http.get('/myEndpoint').then(function(response) {
config = response.config;
});
$httpBackend.flush();
expect(config.property).toBe('check me in a test');
但这几乎是一个集成测试。为什么不创建一个真正的单元测试:
it('should set something on the config', function() {
var input = {};
var config = MyInterceptor.request(input);
expect(config.property).toBe('check me in a test');
expect(config).toBe(input);
});