Skip to content

Could not mock the dependency explicitly asked to mock #22

Description

@cmolina

Hi. I am learning to use ng-improved testing, but when I try to inject the service I am testing

describe('$cart', function() {
  beforeEach(ModuleBuilder.forModules('web')
    .serviceWithMocksFor('$cart', '$api')
    .build());

  it('should return the number of elements in the cart', function() {
    inject(function($cart) {
      expect($cart.count).toBeNumber();
      expect($cart.count).toBeGreaterThan(-1);
    });
  });

I got the following error:

Error: [$injector:modulerr] Failed to instantiate module function ($provide, $filterProvider, $controllerProvider, $compileProvider, $animateProvider) due to:
    Could not mock the dependency explicitly asked to mock: $api
    http://errors.angularjs.org/1.3.16/$injector/modulerr?p0=function%20(%24provide%2C%20%24filterProvider%2C%20%24controllerProvider%2C%20%24compileProvider%2C%20%24animateProvider)&p1=Could%20not%20mock%20the%20dependency%20explicitly%20asked%20to%20mock%3A%20%24api in /home/camolin3/niu/niusushi-website/bower_components/angular/angular.js (line 63)
    minErr/<@/home/camolin3/niu/niusushi-website/bower_components/angular/angular.js:63:12
    loadModules/<@/home/camolin3/niu/niusushi-website/bower_components/angular/angular.js:4154:15
    forEach@/home/camolin3/niu/niusushi-website/bower_components/angular/angular.js:326:11
    loadModules@/home/camolin3/niu/niusushi-website/bower_components/angular/angular.js:4115:5
    createInjector@/home/camolin3/niu/niusushi-website/bower_components/angular/angular.js:4041:11
    workFn@/home/camolin3/niu/niusushi-website/bower_components/angular-mocks/angular-mocks.js:2425:44
    angular.mock.inject@/home/camolin3/niu/niusushi-website/bower_components/angular-mocks/angular-mocks.js:2408:30
    @/home/camolin3/niu/niusushi-website/tests/unit/services/cart.js:14:5

I do not understand what I am doing wrong. Please help.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions