I am trying to write unit test for angularjs controller and run the test using chutzpah from command prompt. I am running the test by calling chutzpah.json. The file inculdes the following:
{
"Framework": "mocha",
"MochaInterface": "tdd",
"Tests": [
{ "Include": "*Test.js" }
]
"References" : [
{"Path": "mocha.js", "IsTestFrameworkFile": "true" },
{"Path": "chai.js" },
{"Path": "angular.js" },
{"Path": "angular-mocks.js" }
]
}
The test I am trying to run is like this (Note: The test as it is now, doesn't really do anything. It is just for to show the problem):/// <reference path="path/to/controller" />
var assert = chai.assert;
describe('MyController: ', function () {
var $rootScope, $scope, $controller;
beforeEach(function () {
angular.mock.module('my.module');
angular.mock.inject(function (_$rootScope_, _$controller_) {
$rootScope = _$rootScope_;
$scope = $rootScope.$new();
$controller = _$controller_;
$controller('MyController', { '$rootScope': $rootScope, '$scope': $scope });
});
});
it('Check needed variables', function () {
assert.isTrue(true, 'Test done');
});
});
If I run the test as it is written above, chutzpah finds the file but not the actual test. If I comment out the inject part of the test, chutzpah finds the actual test. As a newbie to testing, this could also be user error :)