简体   繁体   English

Chutzpah - 找不到变量:模块

[英]Chutzpah - can't find variable : module

I just installed Chutzpah to run Jasmine based unit tests for Javascript. 我刚刚安装了Chutzpah来运行基于Jasmine的Javascript单元测试。 I'm new to Jasmine as well as Chutzpah and angular. 我是Jasmine以及Chutzpah和棱角分明的新手。 I have created a test file for an angular filter. 我为角度滤镜创建了一个测试文件。 The test file is called filters.spec.js and cointains the following code 测试文件名为filters.spec.js,并包含以下代码

 /// <reference path="c:\users\octaviane.cvuintelligence\documents\visual   studio 2013\Projects\PersonalTrainer\PersonalTrainer\Scripts/jasmine.js" />
/// <reference path="c:\users\octaviane.cvuintelligence\documents\visual studio 2013\Projects\PersonalTrainer\PersonalTrainer\Scripts/angular.js" />
/// <reference path="../app.js" />


describe("Filters", function () {
  beforeEach(function () { module('7minWorkout') });
  describe("secondsToTime filter", function () {
    it('should convert integer to time format',
    inject(function ($filter) {
        expect($filter("secondsToTime")(5)).toBe("00:00:05");
        expect($filter("secondsToTime")(65)).toBe("00:01:05");
        expect($filter("secondsToTime")(3610))
        .toBe("01:00:10");
    }));
  });
});

As you can see I referenced angular.js, jasmine.js and the js file where the 7minWorkout module is created. 如您所见,我引用了angular.js,jasmine.js和创建7minWorkout模块的js文件。 I'm brand new to this, so please don't get mad with me. 我是新手,所以请不要生我的气。 While running this test file (right-click the file contents in Visual Studio - Run JS Tests), I get the following errors: Can't find variable: module and Can't find variable: inject . 在运行此测试文件(右键单击Visual Studio中的文件内容 - 运行JS测试)时,我收到以下错误: 找不到变量:module并且找不到变量:inject Please help me out. 请帮帮我。 Thanks. 谢谢。

So, I finnaly got it working by adding a reference in my unit tests file to angular-mocks.js and to the actual JS file where the code I was testing was defined (filters.js) 所以,我通过在单元测试文件中添加一个引用到angular-mocks.js以及我测试的代码定义的实际JS文件(filters.js)来完成它的工作。

For all newbies that find this post, to get Chutzpah for visual studio to actually run you UnitTests for jasmine, you need to reference in your unit tests file the following files: 对于找到这篇文章的所有新手,要让Chutzpah for visual studio实际运行UnitTests for jasmine,你需要在你的单元测试文件中引用以下文件:

  • angular.js angular.js
  • angular-mocks.js 角mocks.js
  • jasmine.js jasmine.js
  • all the JS files form your application that are involved in the testing process - the JS file where you created the angular module / controller / function that you happen to test. 所有JS文件构成了测试过程中涉及的应用程序 - JS文件,您在其中创建了您正在测试的角度模块/控制器/功能。

Hope this helps out someone :) 希望这有助于某人:)

You need to use the jasmine typings (d.ts) in order to write your tests in Typescript. 您需要使用jasmine typings(d.ts)才能在Typescript中编写测试。 Now you only reference jasmine in plain js so module is an unknown keyword. 现在你只引用普通js中的jasmine,所以module是一个未知的关键字。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM