I'm trying to write my first Angular unit test in TypeScript and I'm getting the follow error and can not find out why. If any one has any idea please let me know.
TS2304: Cannot find name 'module'.
test code:
/// <reference path="../typings/karma-jasmine/karma-jasmine.d.ts" />
/// <reference path="../typings/angularjs/angular-mocks.d.ts" />
describe("FooTest", () => {
beforeEach(module("app"));
});
I'm use TSD (TypeScript Definition manager) to manage my TypeScript definitions.
tsd.json
{
"version": "v4",
"repo": "borisyankov/DefinitelyTyped",
"ref": "master",
"path": "typings",
"bundle": "typings/tsd.d.ts",
"installed": {
"jquery/jquery.d.ts": {
"commit": "ef32bff4d15782dbbabf99ecb17ba22119cc2bd2"
},
"angularjs/angular.d.ts": {
"commit": "ef32bff4d15782dbbabf99ecb17ba22119cc2bd2"
},
"karma-jasmine/karma-jasmine.d.ts": {
"commit": "ef32bff4d15782dbbabf99ecb17ba22119cc2bd2"
},
"jasmine/jasmine.d.ts": {
"commit": "ef32bff4d15782dbbabf99ecb17ba22119cc2bd2"
},
"angularjs/angular-mocks.d.ts": {
"commit": "ef32bff4d15782dbbabf99ecb17ba22119cc2bd2"
}
}
}
I'm use IntelliJ IDEA 14
Thanks, Stefan
Recently Angular team commented the global module in angular-mocks
//Use `angular.mock.module` instead of `module`, as `module` conflicts with commonjs.
//declare var module: (...modules: any[]) => any;
In order to make your test compile you need to use full namespace, so angular.mock.module
example:
beforeEach(function () {
angular.mock.module('app');
}
before:
beforeEach(function () {
module('app');
}
after:
beforeEach(function () {
angular.mock.module('app');
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With