Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 443
Octavian Epure Avatar asked Aug 01 '26 20:08

Octavian Epure


1 Answers

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 :)

like image 57
Octavian Epure Avatar answered Aug 04 '26 09:08

Octavian Epure



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!