I have couple questions:
1. Looking
here,
here and some other places I see that there are underscore symbols around some parameters (like
_$httpBackend_). Is that some naming conventions or something else?
2. In my app.js file I have these:
router.when('/campaigns', {
templateUrl: '/partials/items.html',
controller: 'ItemListController',
resolve: resolve
});
resolve contains a resolveFunction returning promise. There is an assignment inside these function:
$rootScope.accountInfo = data;
I am trying to write unit test for ItemListController. When I run Testacular:
info: Testacular server started at http://localhost:9876/
info (launcher): Starting browser Chrome
info (Chrome 25.0): Connected on socket id Z6A2vK9HrZ3LB3go0Z7N
Chrome 25.0 application controllers ItemListController bar === bar FAILED
TypeError: Cannot read property 'created_at' of undefined
at new ItemListController (/home/www/myapp/src/controllers/ItemListController.js:19:120)
at invoke (/home/www/myapp/contrib/angular/angular.js:2809:28)
at Object.instantiate (/home/www/myapp/contrib/angular/angular.js:2819:23)
at /home/www/myapp/contrib/angular/angular.js:4639:24
at null.<anonymous> (/home/www/myapp/test/unit/controllerSpec.js:8:20)
at Object.invoke (/home/www/myapp/contrib/angular/angular.js:2809:28)
at workFn (/home/www/myapp/test/lib/angular/angular-mocks.js:1731:20)
Error: Declaration Location
at window.jasmine.window.inject.angular.mock.inject (/home/www/myapp/test/lib/angular/angular-mocks.js:1717:25)
at null.<anonymous> (/home/www/myapp/test/unit/controllerSpec.js:6:20)
at null.<anonymous> (/home/www/myapp/test/unit/controllerSpec.js:5:5)
at /home/www/myapp/test/unit/controllerSpec.js:1:1
Chrome 25.0: Executed 1 of 1 (1 FAILED)
e 25.0: Executed 1 of 1 (1 FAILED) (0.173 secs / 0.034 secs)
First error caused by calling $rootScope.accountInfo.created_at inside my $rootScope.accountInfo.created_at becaused in is not recieved by resolveFunction described above.
So how can I mock these inside controller test?
What does second error mean?
My test spec below:
describe('application controllers', function () {
var scope;
var ctrl;
beforeEach(module('application'));
describe('ItemListController', function () {
beforeEach(inject(function($rootScope, $controller) {
scope = $rootScope.$new();
ctrl = $controller('ItemListController', {$scope: scope});
}));
it('bar === bar', function () {
expect('bar').toBe('bar');
});
});
});
3. It's too hard to learn unit testing reading the docs on angular website. Is there any tutorials elsewhere? The most difficult parts are mocking promises and injecting.