How to write test case for front-end hack component in kibana plugin?

I've resolved the above issue. But the question is I'm intercepting http request in hack component and adding additional headers. In test cases I'm sending one http backend request and expecting the headers I've added. But after debugging I've realized that when I'm sending backend request it is not coming to the config I've written in hack component. In fact it is not loading hack component at all as far as I know.

My hack component is something like:

uiModules
.get('kibana', ['angular-jwt'])
.config(['$httpProvider', 'jwtOptionsProvider', function Authenticate($httpProvider, jwtOptionsProvider) {
  var refreshPromise;

  jwtOptionsProvider.config({
    tokenGetter: ['$q', '$timeout', 'jwtHelper', function ($q, $timeout, jwtHelper) {
      // setting authentication header
  });

  $httpProvider.defaults.withCredentials = true;
  $httpProvider.interceptors.push('jwtInterceptor');
}]);

And my test case is something like

beforeach(function() {
  angular.mock.module('kibana')
  angular.mock.inject(function(_$http_, _$httpBackend_, _$timeout_) {
      $http = _$http_;
      $httpBackend = _$httpBackend_;
      $timeout = _$timeout_;
     });
  })
})

it('do something', function() {
   $httpBackend.expectGET('/api', function(headers) {
     //checking if header is coming
   }).respond(200, 'data');
   $http.get('/api').then(calling success spy);
})

But it is not even going in hack component. I think I missed to import hack component in test case. But don't know how to do it. Please guide.

It's hard to say based on the code snippets you pasted. $httpBackend looks like it'd be undefined in your test case.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.