我正在尝试在TypeScript中编写我的第一个Angular单元测试,但我得到了跟随错误,但无法找到原因.如果有任何想法,请告诉我.
TS2304: Cannot find name ‘module’.
测试代码:
/// <reference path="../typings/karma-jasmine/karma-jasmine.d.ts" /> /// <reference path="../typings/angularjs/angular-mocks.d.ts" /> describe("FooTest",() => { beforeEach(module("app")); });
我使用TSD(TypeScript定义管理器)来管理我的TypeScript定义.
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" } } }
我使用的是IntelliJ IDEA 14
谢谢,斯特凡
最近Angular团队评论了角度模拟的全球模块
原文链接:https://www.f2er.com/angularjs/142513.html//Use `angular.mock.module` instead of `module`,as `module` conflicts with commonjs. //declare var module: (...modules: any[]) => any;
为了使您的测试编译,您需要使用完整的命名空间,因此angular.mock.module
例:
beforeEach(function () { angular.mock.module('app'); }