Reputation: 29720
I am testing an angular interceptor. I want to check something on the config from the context of a jasmine unit test. Here is the code for the test....
it('should set something on the config', function(){
$http.get('/myEndpoint');
$httpBackend.flush();
expect('????? -- I want to check the config.property here');
});
Here is the production code...
angular.module('app.core').factory('MyInterceptor', function MyInterceptor($injector) {
return {
request: function(config) {
config.property = 'check me in a test';
return config;
},
);
My question is how do I check config.property from a test?
Upvotes: 1
Views: 139
Reputation: 691943
The following should work:
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');
But this is almost an integration test. Why not instead create a real unit 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);
});
Upvotes: 1