3

I'm trying to wrap my head around Typescript, AngularJS, and the ngMock portion. I've seen code to inject a module at the beginning of a unit test like this.

beforeEach(angular.mock.module("myApp"));

I need to provide another service so this works:

beforeEach(module("myApp", function($provide) {
    $provide.value("myService", {
        ...
    });
}));

But if I did

beforeEach(angular.mock.module("myApp", function($provide) {
    $provide.value("myService", {
        ...
    });
}));

The Typescript compiler complains that angular.mock.module only takes one argument. So in the first snippet above, what module is it using? When I go to the definition, it says in the angular-mocks.d.ts:

declare var module: (...modules: any[]) => any;

So what is going on here? I'm not sure if I understand the notation in the definition file to understand if angular.mock.module and module are used the same. Can someone explain this to me?

2
  • is "myApp without end quote a typo? Commented Jul 25, 2014 at 21:39
  • @Edminsson ya just a typo. Writing pseudo code. Will fix. Commented Jul 25, 2014 at 21:47

1 Answer 1

2

I'm not sure if I understand the notation in the definition file to understand if angular.mock.module and module are used the same. Can someone explain this to me?

There is an error in the definition. The following two should be the same: https://github.com/borisyankov/DefinitelyTyped/blob/master/angularjs/angular-mocks.d.ts

    // global module
    declare var module: (...modules: any[]) => any;

    // from angular.mock.module
    module(...modules: string[]): any;
    module(...modules: Function[]): any;
    module(modules: Object): any;

If you get the latest definition file its been fixed: https://github.com/borisyankov/DefinitelyTyped/pull/2564

There is a flip side: In quite a few cases the definitions are even better than the JavaScript lib's documentation.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.