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

(Parth Kalaria) #1

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:

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

    tokenGetter: ['$q', '$timeout', 'jwtHelper', function ($q, $timeout, jwtHelper) {
      // setting authentication header

  $httpProvider.defaults.withCredentials = true;

And my test case is something like

beforeach(function() {
  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.

(Chris Davies) #2

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

(system) #3

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