[英]Angular unit test with TypeScript: TS2304: Cannot find name 'module'
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. 我正在尝试在TypeScript中编写我的第一个Angular单元测试,并且我得到了跟随错误,但无法找出原因。 If any one has any idea please let me know.
如果有任何想法,请告诉我。
TS2304: Cannot find name 'module'.
TS2304:找不到名称'模块'。
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 (TypeScript定义管理器)来管理我的TypeScript定义。
tsd.json 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 我使用的是IntelliJ IDEA 14
Thanks, Stefan 谢谢,斯特凡
Recently Angular team commented the global module in angular-mocks 最近Angular团队评论了角度模拟的全球模块
//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 为了使您的测试编译,您需要使用完整的命名空间,因此angular.mock.module
example: 例:
beforeEach(function () {
angular.mock.module('app');
}
before: 之前:
beforeEach(function () {
module('app');
}
after: 后:
beforeEach(function () {
angular.mock.module('app');
}
My guess: 我猜:
you are using angular-mocks.d.ts
but I don't see angular-mocks.ts
anywhere. 你正在使用
angular-mocks.d.ts
但我没有看到angular-mocks.ts
。
d.ts
files contain only the type definitions, not the actual implementation. d.ts
文件只包含类型定义,而不包含实际实现。 So you will need both. 所以你需要两者。
PS: I think that angular-mocks.ts has only the .js version :) PS:我认为angular-mocks.ts只有.js版本:)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.