mardi 6 octobre 2015

How to handle dependencies of dependencies for karma unit test?

I'm a big newbie in Angular and Karma.

I have a directive, let's say "exchangeDirective" that belongs to module "module.money." This module also contains the child directive of exchangeDirection and an exchangeListingsFactory. The problem is I keep getting this error:

Error: [$injector:unpr] Unknown provider: siteConfigProvider <- siteConfig <- exchangeDirective

I'm not sure where to look or what syntax to use

How do I mock or stub into my factory or service?

beforeEach(module(function($provide) {
$provide.value('ExchangesListingFactory', function() {
      return {}
    })
}))

I've also tried to mock the child directive like this but I run into errors (exchange being child directive)

  beforeEach(module('module.exchangesListing', function($compileProvider) {
    $compileProvider.directive('exchange', function() {
      var fake = {
        priority: 10000,
        terminal: true,
        restrict: 'E',
        template: '<div class="fake">Not the real thing.</div>',
      }
      return fake
    })

Both of the above snippets are in my exchangeDirective.

Aucun commentaire:

Enregistrer un commentaire