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:
Hope this helps out someone :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With