简体   繁体   English

使用TypeScript进行角度单元测试:TS2304:找不到名称“模块”

[英]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.

相关问题 TypeScript错误:TS2304:找不到名称&#39;日期&#39; - TypeScript error: TS2304:Cannot find name 'Date' 带有angular2和咕unt声错误的打字稿TS2304:找不到名称 - Typescript with angular2 and grunt error TS2304: Cannot find name grunt错误TS2304找不到名称 - grunt error TS2304 cannot find name 错误TS2304:找不到名称“地图”。 具有angular 2和.net核心 - error TS2304: Cannot find name 'Map'. with angular 2 and .net core 尽管存在angular.d.ts文件,TypeScript的VS2015内部版本仍给出“ TS2304:内部找不到角度”错误 - VS2015 build of TypeScript gives “TS2304:Build cannot find angular” error despite presence of angular.d.ts file 在Ionic 2中使用Github的Node-Trello-错误TS2304:找不到名称“ require” - Using Github's Node-Trello in Ionic 2 - Error TS2304: Cannot find name 'require' AngularJs + Typescript:错误TS2307:找不到模块&#39;angular&#39; - AngularJs + Typescript: error TS2307: Cannot find module 'angular' TS2307:找不到模块“角度” - TS2307: Cannot find module 'angular' 打字稿tsc错误TS2307:找不到模块&#39;@ angular / core&#39; - typescript tsc error TS2307: Cannot find module '@angular/core' 带有打字稿错误的角度,找不到名称角度 - angular with typescript error, cannot find name angular
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM