简体   繁体   中英

Chutzpah - can't find variable : module

I just installed Chutzpah to run Jasmine based unit tests for Javascript. I'm new to Jasmine as well as Chutzpah and angular. I have created a test file for an angular filter. The test file is called filters.spec.js and cointains the following code

 /// <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. 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 . 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)

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:

  • angular.js
  • angular-mocks.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.

Hope this helps out someone :)

You need to use the jasmine typings (d.ts) in order to write your tests in Typescript. Now you only reference jasmine in plain js so module is an unknown keyword.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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