I'm trying to setup unit testing on my webapp using mocha. My webapp uses AngularJs and since I'm still new to this framework, I'm having a hard time to setup this.
In fact, is there a way to setup this by using nothing else than mocha? I mean, is it possible to setup my unit tests without Karma or any other test runners (and no browser)?
Here's my code to test :
define(['angular'], function (angular) {
var module = angular.module('MyModule', []);
module.controller('MyController', ['$scope', '$window', function ($scope, $window) {
$scope.test = function () {
$window.alert('Not implemented yet.');
};
}]);
return module;
});
And here's my test code:
require("chai");
require('../lib/angular/angular-mocks');
describe("Unit testing example", function() {
beforeEach(angular.mock.module('MyModule'));
it('should test nothing', function() {
expect(true).to.be.true;
})
});
When I try to execute this, I receive this error:
angular.mock = {};
^
ReferenceError: angular is not defined
Thank you for your help!
beforeEachlooks suspicious.beforeEachtakes a function as parameter. Does angular.mock.module('MyModule') return a function? One thatbeforeEachcan use?