Test case for hack component are not executing


(Parth Kalaria) #1

I developed plugin which is only using hack component. I'm not using any other app or server components. I also want to add test cases for this hack component. But when I run the test cases using yarn test:browser it is executing 0 test cases. So is it really possible to write test cases for hack components?


(Lukas Olson) #2

What does your directory structure look like and where are you putting the test files?


(Parth Kalaria) #3

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.


(system) #4

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