I look at the TODO MVC AngularJS example, and I see that the application is defined as a module.
var todomvc = angular.module('todomvc', []);
Inside the controllers, I see that they are defined as:
todomvc.controller('TodoCtrl', function TodoCtrl($scope, $location, todoStorage, filterFilter) {
});
My question is about unit testing ... how do I write unit test for this class?
I tried things like:
describe('TodoCtrl', function () {
var controller;
beforeEach(function () {
controller = todomvc.TodoCtrl;
});
afterEach(function() {
controller = null;
});
describe('addTodo() method', function() {
console.log(controller)
it('should do something', function () {
expect(typeof controller.addTodo).toBe(true);
});
});
});
... but then the "controller" ends with zero or undefined.
Do I need to modify the TODO MVC application so that the function passed to todomvc.controller () is not anonymous?
Any direction would be appreciated as I am very new to Angular.
source
share